How to Sync data between two Salesforce org via Heroku Connect

Salesforce.com Certified Force.com Advanced Developer

Reading List:

Force.com Apex Code Developer’s Guide
https://www.salesforce.com/us/developer/docs/apexcode/

Visualforce Developer’s Guide
http://www.salesforce.com/us/developer/docs/pages/index.htm

Force.com Metadata API Developer’s Guide
http://www.salesforce.com/us/developer/docs/api_meta/

Force.com Migration Tool Guide
http://www.salesforce.com/us/developer/docs/daas/

Introduction to the Force.com Development Lifecycle
https://developer.salesforce.com/docs/atlas.en-us.dev_lifecycle.meta/dev_lifecycle

Apex

  1. Order of Execution of Trigger
    https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm
  2. After triggers execute before declarative business logic features

  3. Which Trigger gets fired in Merge Operation?
  4. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_merge_statements.htm

  5. Read about Undelete Trigger
  6. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_recovered_records.htm

  7. How to Test Triggers?
  8. How to reduce ViewState?
    https://developer.salesforce.com/page/An_Introduction_to_Visualforce_View_State
  9. Email Service and how to Test Email Services?
    Messaging.InboundMailHandler
  10. Describe Method
  11. Difference between Token and describe
  12. Token of Sobject and Sobject field both have getDescribe() method (TRUE)
  13. Too many SOQL(101),
  14. There were many questions on System Log (Developer Console), Debug Log Levels
    https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_debugging_system_log_console.htm
  15. debug log can record database operations, system processes, and errors that occur when executing a transaction or running unit tests. Debug logs can contain information about:

    Database changes
    HTTP callouts
    Apex errors
    Resources used by Apex
    Automated workflow processes, such as:
    Workflow rules, Assignment rules, Approval processes, Validation rules

    Debug Log Categories
    You can specify the following log categories. The amount of information logged for each category depends on the log level:
    Log Category          Description
    Database                 Includes information about database activity, including every data manipulation language (DML) statement or inline SOQL or SOSL query.
    Workflow                 Includes information for workflow rules, such as the rule name, the actions taken, and so on.
    Validation                Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on.
    Callout     Includes the request-response XML that the server is sending and receiving from an external Web service. This is useful when debugging issues related to using Force.com Web services API calls.
    Apex Code               Includes information about Apex code and can include information such as log messages generated by DML statements, inline SOQL or SOSL queries, the start and completion of any triggers, and the start and completion of any test method, and so on.
    Apex Profiling         Includes cumulative profiling information, such as the limits for your namespace, the number of emails sent, and so on.
    Visualforce              Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
    System   Includes information about calls to all system methods such as the System.debug method.

  16. Inner classes may only be declared one level deep
  17. By default, all Apex executes under the System user, ignoring all CRUD, field-level, and row-level security with sharing ignoring

  18. Controller, SOBJECT.addError(),
  19. How to add error messages to Visualforce page

  20. Anonymous block
  21. Note the following about the content of an anonymous block (for executeAnonymous(), the code String):

    • Can include user-defined methods and exceptions.
    • User-defined methods cannot include the keyword static.
    • You do not have to manually commit any database changes.
    • If your Apex trigger completes successfully, any database changes are automatically committed. If your Apex trigger does not complete successfully, any changes made to the database are rolled back.
    • Unlike classes and triggers, anonymous blocks execute as the current user and can fail to compile if the code violates the user’s object- and field-level permissions.
    • Do not have a scope other than local. For example, though it is legal to use the global access modifier, it has no meaning. The scope of the method is limited to the anonymous block.
    • When you define a class or interface (a custom type) in an anonymous block, the class or interface is considered virtual by default when the anonymous block executes. This is true even if your custom type wasn’t defined with the virtual modifier. Save your class or interface in Salesforce to avoid this from happening. Note that classes and interfaces defined in an anonymous block aren’t saved in your organization.
  22. Run as system or user mode execute System.runAs()
  23. Using Constructors
  24. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_constructors.htm

  25. Access Modifiers
  26. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_access_modifiers.htm

    Very good understanding of Static and Global class.

  27. After undelete trigger – accounts are deleted and the corresponding contacts are deleted – accounts are then undeleted. After undelete trigger of account fires the undelete trigger of contacts fires : False – Only the undelete of the parent object fires (in this case account)
  28. Webservice methods always execute as System model
  29. Classes that are virtual or abstract can also be public
  30. You cannot add an abstract method to a global class after the class has been uploaded in a Managed – Released package version.
  31. If the class in the Managed – Released package is virtual, the method that you can add to it must also be virtual and must have an implementation.

  32. A callout from a Trigger event cannot be synchronous TRUE
  33. HTTP callouts from a trigger must be asynchronous using the @future annotation with the callout=true syntax
    @future(callout=true)

  34. Standard controller action methods,
  35. Save, quick save, edit, view, cancel, list

  36. Exception
  37. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_exception_statements.htm

  38. How to create REST request and how to test it.
  39. Instanceof: If you need to verify at run time whether an object is actually an instance of a particular class, use the instanceof keyword. The instanceof keyword can only be used to verify if the target type in the expression on the right of the keyword is a viable alternative
    for the declared type of the expression on the left.

Visualforce

  1. How to create Custom Component?
  2. Custom Component Markup

    <apex:component>
    <apex:attribute name=”record” description=”The type of record we are viewing.”
    type=”Object” required=”true”/>
    <apex:pageBlock title=”Viewing {!record}”>
    <apex:detail />
    </apex:pageBlock>
    </apex:component>
    http://www.salesforce.com/us/developer/docs/pages/Content/pages_comp_cust_elements_markup.htm

  3. How to add custom (Create Visualforce) button on List Views?
  4. Difference in <apex:Actionsupport>, <apex:ActionFunction> and <apex:ActionPoller>?
  5. How to use Visualforce Template?
  6. All templates defined using <apex:composition> must have one or more child <apex:insert> tags. An <apex:insert> tag indicates to pages that import the template that a section needs a definition. Any Visualforce page that imports a template using <apex:composition> must use <apex:define> to specify the content of each <apex:insert> section of the template.

    You can create a skeleton template that allows subsequent Visualforce pages to implement different content within the same standard structure. To do so, create a template page with the <apex:composition> tag.

    The following example shows how you can use <apex:composition>, <apex:insert>, and <apex:define> to implement a skeleton template.
    http://www.salesforce.com/us/developer/docs/pages/Content/pages_templates_composition.htm

  7. What is supported in <apex:attribute> tag?
  8. An <apex:attribute> tag requires values for the name, description, and type attributes:
    The name attribute defines how the custom attribute can be referenced in Visualforce pages. names for attributes must be unique within a component.
    The description attribute defines the help text for the attribute that appears in the component reference library once the custom component has been saved. The custom component is listed in the reference library with the standard components that are also available.
    The type attribute defines the Apex data type of the attribute. Only the following data types are allowed as values for the type attribute:
    Primitives, such as String, Integer, or Boolean.
    sObjects, such as Account, My_Custom_Object__c, or the generic sObject type.
    One-dimensional lists, specified using array-notation, such as String[], or Contact[].
    Maps, specified using type=”map”. You don’t need to specify the map’s specific data type.
    Custom Apex classes.
    http://www.salesforce.com/us/developer/docs/pages/Content/pages_comp_cust_elements_attributes.htm

  9. What is sequence of execution of Visualforce in GET Request?
  10. http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_get_request.htm

  11. Sequence of execution of Visualforce in POST Request?
  12. http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_postback_request.htm

  13. Examples of Visualforce page execution order
  14. http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm
    Static Resource And Document key point:
    Whether can be referenced by Name
    Whether SR size can bigger than Document, (Both a 5MB)
    Whether Use ZIP, JAR Format
    To reference a file in an archive, use the URLFOR function. Specify the static resource name that you provided when you uploaded the archive with the first parameter, and the path to the desired file within the archive with the second. For example:
    http://www.salesforce.com/us/developer/docs/pages/Content/pages_resources_reference.htm

  15. renderAs
  16. <apex:page renderAs=”pdf”>
    http://www.salesforce.com/us/developer/docs/pages/Content/pages_output_pdf_renderas.htm

  17. To access a datatable with id=”tableID” contained in a pageblock with id=”blockID” what expression would you use? $Component.blockID.tableID,
  18. How Visualforce properties (Getters and Setters) works?
  19. http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_controller_getter_methods.htm

  20. How to create Controller Extensions?
  21. http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller.htm

  22. Describe how to test Force.com page controllers
  23. Defining Action Methods
  24. Action methods perform logic or navigation when a page event occurs, such as when a user clicks a button, or hovers over an area of the page. Action methods can be called from page markup by using {! } notation in the action parameter of one of the following tags:
    <apex:commandButton> creates a button that calls an action
    <apex:commandLink> creates a link that calls an action
    <apex:actionPoller> periodically calls an action
    <apex:actionSupport> makes an event (such as “onclick”, “onmouseover”, and so on) on another, named component, call an action
    <apex:actionFunction> defines a new JavaScript function that calls an action
    <apex:page> calls an action when the page is loaded

  25. How to concatenate two String in Visualfroce page <&, +>
  26. http://gw8311.wordpress.com/tag/visualforce-page/

Testing

  1. Difference in System.AssertEquals, System.Assert?
  2. IsTest Class
  3. Classes and methods defined as isTest can be either private or public. The access level of test classes methods doesn’t matter. This means you don’t need to add an access modifier when defining a test class or test methods. The default access level in Apex is private. The testing framework can always find the test methods and execute them, regardless of their access level.
    https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_unit_tests.htm

  4. runAs
  5. https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm

  6. startTest Test.stopTest
  7. In addition to the Limits methods, use the startTest and stopTest methods to validate how close the code is to reaching governor limits.
    https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_start_stop_test.htm

  8. When testing a trigger you have created how many records should be included in the test case to ensure the total # of SOQL queries governor limit is not exceeded A minimum of 101 – The governor limit is 100 SOQL queries per transaction

Database

  1. How to use Dynamic Apex, Dynamic SOQL and Dynamic SOSL?
  2. Read about SOQL Clauses like FOR UPDATE, ALL ROWS
  3. https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_locking_statements.htm

  4. Whether SELEC a.A, a.B FROM sOjbect where a.A = a.B correct? Where compile error or runtime error?

Deployment

  1. When to use Package, ChangeSet and Force.com Migration tool?
  2. File names of ANT Migration and there usage?
  3. build.properties
    build.xml
    package.xml files

  4. How to delete something using Migration Tool?
  5. When to use Sandboxes and when to use Developer Account?
  6. Given a scenario, determine whether to use package or metadata deployment
  7. Describe how to manage sandbox environments
  8. List and describe the various development and test environments available on the Force.com platform
  9. Apex can be authored in a production environment?
    “You can’t develop Apex in your Salesforce production organization.”
  10. What choice is required for deploy changes from sandbox to production

Materials for Salesforce Developer

1. All the Salesforce study material could be finding from Developer Force: http://developer.force.com
2. Certificated Administrator Guid: http://certification.salesforce.com/SG_CertifiedDeveloper.pdf?v=8
3. Other helpful resources:
Online course: Application Essentials
Online course: Analytics as a Service
Online course: Data Management
Online course: Designing Apps for Multiple Users
Online course: Implementing Business Process
Online course: Visualforce Pages
4. An Introduction to Custom Application Development in the Cloud (Force.com Platform Fundamentals): http://www.salesforce.com/us/developer/docs/fundamentals/salesforce_creating_on_demand_apps.pdf
5. Whitepaper: A Comprehensive Look at the Force.com Cloud Platform: http://wiki.developerforce.com/page/A_Comprehensive_Look_at_the_Force.com_Cloud_Platform
6. Integration Patterns and Practices :http://wiki.developerforce.com/page/Integration_Patterns_and_Practices
7. Force.com Platform Glossary: http://www.salesforce.com/us/developer/docs/platformGlossary/salesforce_platform_glossary.pdf
8. Building Custom Objects, Tabs and Releated Lists: https://na1.salesforce.com/help/doc/en/salesforce_studio_cheatsheet.pdf
9. Data Loader Guide: https://na1.salesforce.com/help/doc/en/salesforce_data_loader.pdf
10. Development Lifecycle Guide: http://www.salesforce.com/us/developer/docs/dev_lifecycle/salesforce_development_lifecycle.pdf
11. Which API Should I Use?: https://help.salesforce.com/HTViewHelpDoc?id=integrate_what_is_api.htm&language=en_US
12. API Usage Limits: https://help.salesforce.com/apex/HTViewHelpDoc?id=integrate_api_rate_limiting.htm&language=en_US
13. An Introduction to Force.com Apex Code: http://wiki.developerforce.com/page/An_Introduction_to_Apex
14. An Introduction to Apex Code Test Methods: http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
15. An Introduction to the Force.com Database: http://wiki.developerforce.com/page/An_Introduction_to_Force_Database
16. Apex Code Best Practices: http://wiki.developerforce.com/page/Apex_Code_Best_Practices
17. An Introduction to Environments: http://wiki.developerforce.com/page/An_Introduction_to_Environments
18. An Introduction to Visualforce: http://wiki.developerforce.com/page/An_Introduction_to_Visualforce
19. An Introduction to the Force.com IDE: http://wiki.developerforce.com/page/An_Introduction_to_Force_IDE

Materials for Salesforce Administator

1. All the Salesforce study material could be finding from Developer Force: http://developer.force.com

2. Certificated Administrator Guid: http://certification.salesforce.com/SG_CertifiedAdministrator.pdf?v=13

3. Other helpful resources:

Online course: Analyze Your Data Your Way with Reports

Online course: Administration Essentials for the Service Cloud

Online course: Configure Salesforce with Custom Fields

Online course: Creating Your Salesforce Community

Online course: Customizing Profiles to Align with Your Business Needs

Online course: Getting a Head Start with Chatter

Online course: Getting Started with Managing Data

Online course: Managing Users and Troubleshooting Login Issues

Online course: Salesforce Mobile

Online course: Summarize Your Data with Highlights, Charts, and Dashboards

4. An Introduction to Custom Application Development in the Cloud (Force.com Platform Fundamentals): http://www.salesforce.com/us/developer/docs/fundamentals/salesforce_creating_on_demand_apps.pdf

5. Whitepaper: A Comprehensive Look at the Force.com Cloud Platform: http://wiki.developerforce.com/page/A_Comprehensive_Look_at_the_Force.com_Cloud_Platform

6. Supported Browsers: https://na1.salesforce.com/help/doc/en/salesforce_supported_browsers_cheatsheet.pdf

7. Force.com Platform Glossary: http://www.salesforce.com/us/developer/docs/platformGlossary/salesforce_platform_glossary.pdf

8. Building Custom Objects, Tabs and Releated Lists: https://na1.salesforce.com/help/doc/en/salesforce_studio_cheatsheet.pdf

9. Data Loader Guide: https://na1.salesforce.com/help/doc/en/salesforce_data_loader.pdf

Non-selective query against large object type in Pricebook2

select Id, Name, isStandard from Pricebook2 from Apex code occurred System.QueryException: Non-selective query against large object type (more than 100000 rows)
this code works fine with JP DEV yesterday, occurred this exception this morning without changes.

1. In the JP FULL only have two price books shouldn’t have this exception from apex code.

11:21:31.173 (173260000)|SOQL_EXECUTE_BEGIN|[27]|Aggregations:0|select Id, Name, isStandard from Pricebook2
11:21:31.174 (174159000)|EXCEPTION_THROWN|[27]|System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
11:21:31.174 (174565000)|HEAP_ALLOCATE|[27]|Bytes:463
11:21:31.174 (174649000)|FATAL_ERROR|System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

Trigger.ProductSalesCountryAIU: line 27, column 1
11:21:31.174 (174676000)|FATAL_ERROR|System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

2. Execute SOQL ([SELECT Id, Name, isStandard FROM Pricebook2]) in anonymous call directly, works fine.

28.0 APEX_CODE,FINER;APEX_PROFILING,FINE;CALLOUT,INFO;DB,INFO;SYSTEM,FINEST
Execute Anonymous: system.debug(‘*** ‘ + [SELECT Id, Name, isStandard FROM Pricebook2]);
11:20:29.018 (18431000)|EXECUTION_STARTED
11:20:29.018 (18449000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
11:20:29.018 (18901000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1
11:20:29.019 (19030000)|STATEMENT_EXECUTE|[1]
11:20:29.019 (19045000)|STATEMENT_EXECUTE|[1]
11:20:29.019 (19068000)|HEAP_ALLOCATE|[1]|Bytes:4
11:20:29.019 (19084000)|HEAP_ALLOCATE|[1]|Bytes:43
11:20:29.019 (19115000)|HEAP_ALLOCATE|[1]|Bytes:4
11:20:29.019 (19505000)|SOQL_EXECUTE_BEGIN|[1]|Aggregations:0|select Id, Name, isStandard from Pricebook2
11:20:29.064 (64986000)|SOQL_EXECUTE_END|[1]|Rows:2
11:20:29.065 (65022000)|HEAP_ALLOCATE|[1]|Bytes:12
11:20:29.065 (65049000)|HEAP_ALLOCATE|[1]|Bytes:119
11:20:29.065 (65254000)|HEAP_ALLOCATE|[1]|Bytes:12
11:20:29.065 (65308000)|SYSTEM_METHOD_ENTRY|[1]|String.valueOf(Object)
11:20:29.065 (65380000)|HEAP_ALLOCATE|[1]|Bytes:130
11:20:29.065 (65400000)|SYSTEM_METHOD_EXIT|[1]|String.valueOf(Object)
11:20:29.065 (65418000)|HEAP_ALLOCATE|[1]|Bytes:134
11:20:29.065 (65447000)|SYSTEM_METHOD_ENTRY|[1]|System.debug(ANY)
11:20:29.065 (65464000)|USER_DEBUG|[1]|DEBUG|*** (Pricebook2:{Name=JP10, Id=01sO000000014RYIAY, IsStandard=false}, Pricebook2:{Name=標準価格表, Id=01s10000000HuLWAA0, IsStandard=true})
11:20:29.065 (65479000)|SYSTEM_METHOD_EXIT|[1]|System.debug(ANY)
11:20:29.756 (65532000)|CUMULATIVE_LIMIT_USAGE
11:20:29.756|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 2 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of code statements: 1 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

“we had an issue with the statistics we store for pricebook2, which was giving incorrect estimates for our optimizer. In your case, it was suggesting there was > 100k rows”

How to query date fields in SOQL

System.CalloutException: handshake alert: unrecognized_name

Case Subject: Sandbox cs15 cannot access CastIron
Case Description: “https://cs15.salesforce.com” call out to “https://cloud2-na1.castiron.com/env/Development/rest?object=DMU” occurred “System.CalloutException: handshake alert: unrecognized_name”, call out was worked fine on Aug 14, but from Aug 15 got this callout exception.

Please refer to Anonymous execution result attached, the same code can run on cs17, so we can sure the CastIron service is fine.
problem should be cs15 cannot identify CastIron, please help us to resolve this problem.

The Source of the problem we have confirmed from our Backline support was a change on CS15 instance wherein the JDK version was changed to version 7 which inturn caused a side effect causing this issue.

Find the weekday in Apex Date and Datetime field

system.debug(system.now().format(‘EEEEE’));

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: system.debug(system.now().format(‘EEEEE’));
09:29:22.554 (554800000)|EXECUTION_STARTED
09:29:22.554 (554814000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
09:29:22.555 (555383000)|USER_DEBUG|[1]|DEBUG|Monday
09:29:22.632 (555433000)|CUMULATIVE_LIMIT_USAGE

system.debug(system.now().format(‘EEE’));

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: system.debug(system.now().format(‘EEE’));
09:29:55.050 (50859000)|EXECUTION_STARTED
09:29:55.050 (50871000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
09:29:55.051 (51521000)|USER_DEBUG|[1]|DEBUG|Mon
09:29:55.296 (51574000)|CUMULATIVE_LIMIT_USAGE

However date type field don’t have this format function, to find the weekday for date field, you have to convert the date to datetime.
Date cDate = Date.Today();
datetime cDatetime = datetime.newInstance(myDate.year(), myDate.month(), myDate.day());
system.debug(myDatetime.format(‘EEEEEE’));

http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

Force.com Best Practices

General Principles

  1. Speed to business value is more important than technical achievement.
  2. Architect for change, design and build with the understanding that things change frequently.
  3. Keep it sample
  • Use any approaches whichever improve user experiences.
  • Use declarative development options as the first response to a non-standard requirement.
  • Code when mandatory, make sure you do need this code, but design for reuse and modularity.
  1. Build common functionality for common processes
  • Focus on common business process before building functionality
  • Solutions should provide value to widest possible audience
  1. Align with enterprise wide initiatives
  • Customer master, product master, etc
  • Align with global counterparts to support reusable assets across programs.
  1. Follow industry design patterns
  • Single trigger per object, unique check on junction objects.
  • Use AppExchange apps for patterns, research and user(if applicable)
  1. Build for the scale required
  2. Test driven development, write comprehensive unit test code first, design and build to pass them.
  3. Pay down technical debt continuously, dedicate resource to refactor and optimize continuously.
  4. Document in the application when necessary
  • Brief, contextual documentation is more valuable than static documentation maintained outside the application.
  • Populate description fields wherever they exist with relevant information about the business and technical reasons for the item.
  1. Design and naming the metadata including object, fields, error messages, etc in English, then translate the labels. No Chinese, German, Japanese.
  2. Program and document Apex Code, Visualforce page in English, make sure other developers able to read and maintenance your code.

Customer Object

  1. Provide custom object description and help if possible.
  2. Make sure the object label and object name consistent, it’s hard to change the object API name once it’s been written in Apex code or referenced to other components, but do it right at the first, when found the differences, as later more troubles would comes without change it.
  3. When creating an object think more about OOP theory, if the object really needed or could being merged with other objects.
  4. When creating a record type for an object, think it’s really need a record type or another object, don’t mix multiple things into one object, one object for one kind of things.
  5. Explain why an object has been created; build major relationship with other objects, what overall functionality or business process it supports and any identifiers from other tracking system for user scenarios, requirement or processes.
  6. Identify whether the custom object need Activity Tracking and disable it if not needed rather than just remove from the related list on the page layouts. This removes the object from the list of “Related To” on the Tasks and Events this provides a cleaner experience for the users.
  7. “Allow Reports” if the object needs reporting, this could automatically create or update the report types, but take care about the new Master-Detail relationship, this would cause the record type changed, and influence the existing reports.
  8. Make sure object (or master object in the Master-Detail relationship) and report type “Deployment Status” is “Deployed”, this make sure object, tab and report type available to all users.
  9. Create a tab for the objects need searches, but “Hidden” or “Default Off” it if don’t need access the records from the tab directly or don’t want to show it on the menu bar.

Custom Field

  1. Provide custom field description and help if possible, explain why a field has been created, what overall functionality or business process it supports and any identifiers from other tracking system for user scenarios, requirement or processes.
  2. Custom fields should not normally be set as required in the field definition. If needed, they can be designed as page layout level required or a validation rule, this convenience when migrating legacy data or data clean up as might really missed data for the fields in particular records.
  3. Custom field API names should keep consistence with field label with space replaced with underscores and a suffix of “__c” is added automatically, and change the API name once changed the field label.
  4. Create a new fields with the same properties to replace the existing field, then delete the old field would be easier, but take care about the column field in list view, relative list, report and dashboard.
  5. Make sure the new custom fields is be added to existing report types.
  6. When naming an identified field, capitalized the “ID” part of the name (ie: SAP ID vs SAP Id).
  7. Fields with technical purpose but won’t show to users, add ‘*’ prefix to fields label and ‘X’ prefix in the API name, put fields in the “System Information” section and remove from page layouts before deploy them to production.

Validation Rule

  1. All the validation rule must have a suffix “&& NOT($User.Ignore_Validation_Rules__c)” allow for ignore the rule globally via a flag on the user record, this convenience when import legacy data migration and data clean up.
  2. When creating a new validation rule, its impact on existing and future unit test, data integration and data migration should be evaluated and documented, this is especially important when considering impact on 3rd party AppExchange application where vendor supplied unit test cannot be modified to accommodate the new validation rules.
  3. Validation rule error messages should be displayed next to the field causing the validation rule to fire so the user can see and correct the error in the context is was raised,
  4. If the rule is validated several fields, the error message should be displayed next to the field that could be modified to clear the error condition or at the top of the page.
  5. Validation rule shouldn’t use environment specific ID’s as port of any criteria, Name should be use instead, For example include profiles, record types, etc. this make migration from one environment to another much easier. This is a general rule but sometimes cannot be avoided in case the ID could be merged in a Custom Setting for ease of maintenance.

Page Layout

  1. When positioning a large text area (Rich text) field in an existing 2 column layout, create a new 1 column hidden section to place the field and do not display the header on the detail or edit pages, this creates the illusion that the 2 columns and 1 column sections are part of the same section and does not make the large text area appear cramped.
  2. The standard “System Information” section header should be visible on all page layouts and should contain the “Created By / Last Modified By” fields at a minimum.
  3. Add “Submit for Approval” button and approval history section to the records need approval request, but remove approval button from the records don’t need approval, training users once see the button then approval needed, otherwise not necessary.
  4. Have “Sharing” button for “Private” sharing object.
  5. “Descending” sort the related list to keep latest records at the top of the list.
  6. Puts the direct master (parent) field in the first section at the top left position.

Workflow

  1. Any workflow that has an action sends an email or outbound message should have a description that end with [Production Only] so these rules can be identified and disabled in the sandboxes, and not to confuse end users with messages from development and sandboxes environments too.
  2. Workflow rule shouldn’t use environment specific system ID’s as port of any criteria, Name should be use instead, For example include profiles, record types, etc. this make migration from one environment to another much easier. This is a general rule but sometimes cannot be avoided in which case the ID could be merged in a Custom Setting for ease of maintenance.
  3. All the workflow rules must have a suffix “&& NOT($User.Ignore_Workflow_Rules__c)” allow for ignore the rule globally via a flag on the user, this convenience when import legacy data migration and data clean up.

Approval Process

  1. General, lock the record after approval
  2. Add “Record Creator” into the Initial Submitters
  3. Allows system administrator and current approver to edit the record.
  4. Put the approval history in the record page layout.
  5. Custom status field for the record need approval.
  6. Allow approvers to access the approval page from the mobile devices.
  7. Allow submitters to recall approval requests

User

  1. Make sure Time Zone setting is correctly.
  2. If received Approval request emails too much, the option could be set as “Never” but send a report to daily remind related users.
  3. “Ignore Workflow Rules” checkbox ignore the workflow rules for specified user
  4. “Ignore Validation Rules” checkbox ignore the validation rule for specified user
  5. “Ignore Triggers” checkbox ignore the trigger specified user
  6. Grant modify all permission users to integration users, but restrict the login hours and IP Ranges.

Profile

  1. Without the exception of the “System Administrator” standard profile, only custom profiles should be used. Custom profile allows customize the permissions and testing whereas standard profile does not. Custom profile could be clone standard profile then customized according to the requirements.
  2. Standard profile has very limited customization capability.
  3. In order to identify a profile as being customized as a glance, all custom profile naming should begin with “Project Name” like “DELL Sales”, etc, or locale code like “DE Sales”, “CH Sales”, etc.
  4. For system maintenance service temporary not available, system administrator could change the Login Hours and Login IP Range to restrict normal user profiles from login to the updating system.
  5. Make sure Login Hours and Login IP Range allows system administrator to login system anytime.
  6. Enable/Disable the class and page security for the relative profiles.

Report

  1. Reports that are used to display on dashboards should have names with prefix “DB- “.
  2. Each dashboard should have its own folder to contain the reports and should have a name with prefix “DB_”
  3. Reports that’s are generated as part of a solution and considered of the overall application should be store in the “App Reports” folder.
  4. Report should be named as descriptively as possible and the description of the report should be in the form of a question the report is trying to answer, for Example:
  • Report Name: DE Win Rate
  • Report Description: What is the Win Rate for DE?
  1. Train the users “Drill Down” the reports.

Dashboard

  1. Dashboards that are accessible to a large set of users and that require access across objects and records that users may not have access to should have a running user of “Admin”.
  2. Run dashboard as logged-in user if possible, this only display user related data.
  3. Dashboard accessible could be controlled by dashboard folder.
  4. Show dashboard chart in “Wide” column.
  5. You cannot assign the colors in the chart, all the chart column displayed randomly.

Custom Label

  1. Apex methods names should be considered verbs for naming purposes; they should always be named for the action they are performing. The first letter of the method name should in low case but if the method name contains multiple words, first letter of each work after the first word should be capitalized.

Correct: ContactRelationships.getOrphaned();

Incorrect: ContactRelationships.GetOrphaned();

Incorrect: ContactRelationships.Orphaned();

Incorrect: ContactRelationships.orphanedMethod();

Apex Class

  1. Apex classes should always include a header at the top of the class according to the following template; the change history should be updated whenever the class is modified.

/**************************************************************************************************

* Name: OpportunityProductCreateExt

* Object: Product__c (Product)

* Requirement: R000001

* Purpose:

* Author: Allen Zhang (allen.zhangyilun@gmail.com)

* Create Date: 2012-07-03

* Modify History:

* Allen    2012-07-03    Initialize

***************************************************************************************************/

 

  1. The first character should always be capitalized and contain only alphanumeric letter. If multiple words are part of the name, first letter each word should be capitalized.
Class Type Description Correct Incorrect
Controller “Con” suffix for object name.

“Object + Con”

AccountCon Accountcon

accountcon

AccountController

Extension “Ext” suffix for extensions of standard controllers, “Object + Action + Ext” AccountCreateExt AccountCreateext

accountcreateext

AccountCreateExtension

Web Service “WS” suffix for object name.

“Object + WS”

AccountWS Accountws

AccountWs

Test Class “Test” suffix for controller, extension name.

“Object + Con + Test”

“Object + Action + Ext+ Test”

“Object + WS + Test”

AccountConTest

AccountCreateExtTest

AccountWSTest

Utility Common functions “Util” suffix for utility class name AccountUtil Accountuti

accountUti

AccountUti

 

Apex Method

  1. Apex methods names should be considered verbs for naming purposes; they should always be named for the action they are performing. The first letter of the method name should in low case but if the method name contains multiple words, first letter of each work after the first word should be capitalized.

Correct: ContactRelationships.getOrphaned();

Incorrect: ContactRelationships.GetOrphaned();

Incorrect: ContactRelationships.Orphaned();

Incorrect: ContactRelationships.orphanedMethod();

 

Visualforce Page

  1. Do not hardcode picklists in Visualforce pages; include them in the controller or extension instead.
  2. JavaScript and CSS should be included as Static Resources allowing the browser to cache them
  3. Reference CSS at the top and JavaScript the bottom of Visualforce pages as this provides for faster page loads.
  4. Mark controller variables as “transient” if they are not needed between server calls. This will make your page load faster as it reduces the size of the View State.
  5. Use <apex:repeat> to iterate over large collections.
  6. Use the cache attribute with the <apex:page> component to take advantage CDN caching when appropriate
  7. Avoid use unsafe components for renders PDFs

Apex Trigger

  1. General one trigger per sObject with all the events handled (added as the real needs) and business logic abstracted into separate logic piece of code.
  2. Use a consistent naming convention including the object name, like following

Correct: Account, Opportunity, Case

Incorrect: trgAccount

Incorrect: triggerAccount

  1. Use Collections in SOQL “WHERE” clauses to retrieve all records back in single query
  2. Execute DML statements using collections instead of individual records per DML statement,
  3. Minimize the number of data manipulation language (DML) operations by adding records to collections and performing DML operations against these collections.
  4. Triggers should be “bulkified” and be able to process up to 200 records for each call.
  5. Minimize the number of SOQL statements by preprocessing records and generating sets, which can be placed in single SOQL statement used with the IN clause.

Apex Unit Test

  1. It is recommended to think about and preferably write test cases BEFORE start the logic code, think of and build the test cases and develop to pass them as this focuses thought on the problem rather than the solution.
  2. Test methods should strive to only test a single piece of functionality whereas functional tests should test several pieces of functionality together.
  3. Test should be contained in a separate class from the class it testing, consolidated test classes for all classes and annotated with “testmethod” to avoid having test code count against org code limits.
  4. Tests should strive to 100% code coverage but is not the measure of completion.
  5. Test should create any data needed as part of the test, Tests should not rely on specific pieces of data already existing in any environment such as specific IDs or data sets.
  6. Test should always test business logic in a bulk fashion; records should be passed to business logic to verify it operates when more than 1 record is passed to it. If appropriate, test with bulk records but balance the execution time with risk.
  7. For testing logic on large data sets that may hit governor limits, create the test data first then use Test.startTest() and Test.stopTest() to execute the logic.
  8. If a class being tested contains business logic that affects record sharing, use System.runAs() to run test in a particular user (which should be created as part of the test) to ensure the sharing logic operates when not running in system mode.

Change Set

  1. Before start the change set, run all test in production make sure system still running correctly before new deployment, if not fix the problems before new change set.
  2. Only add new and changed components into the change set, don’t put not changed components in change set.
  3. Validate the change set before deploy it.
  4. Sequence the change sets, metadata first, then Apex code and Visualforce Page.
  5. Bring the profile from sandbox to the production, this would bring the field level security and page layout assignment.
  6. Take care of the Login Hours and IP Ranges in sandbox and production; don’t override the setting in production.
  7. Download the metadata and compare the XML files with diff tools, make sure all the changes had been deployed.

DataLoader

  1. Check the server host URL once login failures.
  2. Check “Insert null values” if need clear data in Salesforce.
  3. Check the “Time Zone” this make the create/modify time stamp correct in system.

 

Reference

Force.com Programming Best Practices

http://blog.jeffdouglas.com/2010/10/21/force-com-programming-best-practices

Testing Best Practices

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_testing_best_practices.htm|SkinName=webhelp

Salesforce Deployment Checklist

Integration Checked
Change the connection IP, Username and Password to target production environment
Change integration Username, Password and permission to Salesforce.com
Make sure integration server have access to Salesforce.com production IP

Deployment
User license ready in production
Enable Multiple-Currency and add exchange rate
Create Custom Fiscal Years
Create Profile and Role hierarchy in production
Check the IP Range and Login Hours
Sharing Rule Setting
Identify Users and confirm the login and test time
Create users with corresponding SSO
Configuration and code change set including Apex class, Apex trigger and Visualforce page
Enable class and page for the profiles
Force.com IDE and WinMerge compare the field level security of the standard object in profiles
Translation of UI labels and messages
Create List View in each tab
Update report id in buttons or links
Update fields Id in pre-filled buttons or links
Remote Sites Setting in Security to allow integration endpoint
Regression Testing and Ad-Hoc test

Data Migration
Check data storage
Temporary change setting if necessary
Change relative workflow evaluation rule to “Every time a record is created or edited”
Check “Ignore Validation Rules” checkbox for operation user
Check “Ignore Trigger and Workflow” checkbox for integration user
Data template ready
Data load process defined
Import .csv file ready
Field mapping .mdl file ready
Data Load Execution
Lead
Account
Contact
Account Team
Product, Price Book (CNY, USD, EUR)
Opportunity, Opportunity Product
Sales Team
Case
Case Team
Monitor data import progress
Data validation by report
Testing issue resolution
Test Report

Release Note
Requirement list
Ticket list
Bug List