Naming Conventions and Best Practices in Salesforce Development

Classes-                                   UpperCamel Case

Methods and variables -         lowerCamelCase

Constants-                               CONSTANT CASE

HTML-                                       lower_snake_case

When in doubt, be consistent


Triggers

1) Begin with a logic to allow bypassing(Can use a Class/Custom Setting) of the trigger when necessary.

2) Use trigger helper and handler patterns.

3) Keep as much logic as possible out of the trigger and trigger handler.

4) Limit logic used in trigger helper as much as possible; break functionality down into smaller classes to keep helper manageable as this class will be used by the entire wing.



Async Apex

1) Run all asynchronous apex under the user the Admin User.

Future

1) Avoid using future in triggers - salesforce does not allow asynchronous calls to be made while a synchronous process is running.

Batch

1) Keep logic out of batch class as much as possible.

2) Increased governor limits help with more complex operations.

3) Helps avoid mixed DML operations.

Schedule

1) Similar use cases to batch, but used when a job needs to be run regularly.


Unit tests

1) Test class names should always end in "_Test".

    Ex: Sample Class will have a test class named SampleClass_Test.

2) Use a @TestSetup method to set up any test data - best practice and speeds up runtime significantly.

3) Use Test.startTest() and Test.stop Test() to make sure all asynchronous apex finishes before asserts.

4) Use asserts to validate code behavior.

5) Test each public method - positive and negative cases.

6) Aim for 90% test coverage.

7) Should pass in regardless of what environment it is in with the same code coverage amount.

8) Should be able to be run at any time.


Profile considerations when adding a new field or other item requiring permissions

1) When adding a new required field, do not include any permissions as they are meant to be visible to all users

2) Admin - Read/Edit.

Set to Read Only if the field is an Auto Number, Summary, or Formula.

3) Analytics Cloud Integration User - Read Only.

4) Read Only Admin - Read Only.

5) All other profiles that do not need access should be added with Read and Edit set to false.


Comments

Popular posts from this blog

What are Duplicate Rules and Matching Rules? How to Invoke Duplicate and Matching Rules in Salesforce without performing DML operations?

Apex Best Practices

LWC Best Practices