- Use header comments on top classes as below:
/**
@
name :
@
author :
@
date :
@
description :
@
VF page Name :
*/
- Variable/method names needs to be in camelCase as possible. Like creatCase(), getClosedWonOpportunity() etc.
- Variables names must be meaningful as possible, don't like x, y etc
- Use curly braces with same line instead of next line in if/else and loops constructs as below:
}
- Comments at on every possible complex logic, on top of each methods also about its working.
- Keep method as possible small , if going logic more than 50 rows, then break that into other method.
- Test classes must be meaningful, means must have asserts of the main logic, must have coverage near to 80% as possible (at-least 75% is required), use separate test class to cover each separate apex class.
- Use proper Oops concept as possible , means use private where ever possible, extends, method overriding , method overloading etc.
- Don’t hard code ids and any hard code values in code, use query to fetch data or in test classes make new objects.
- Don’t hard code message or error text, try to use Label as possible (If client says).
- Use components as possible for header, footer in pages.
- use standard apex tags as possible.
- Whenever possible make your Utility class which has useful, re-used methods and put your methods in that and use that class in every class logic.
- If any trigger logic is very big, then try to make one class and put your logic in that class and call that class in your trigger. Keep trigger small and as simple as possible.
- Check if condition before using the list. eg:
if(ContactList.size() > 0)
{bla bla}
- Avoid Nested loops, which may cause maximum script statements governor limits to be hit. Should make use of Maps to avoid nested loops.
NOTE: The aforementioned Best Practices are according to
me. Salesforce itself output their own Best Practices. I have cited and
summarized some of the excerpts it.