Tuesday 28 January 2014

Best practices in apex development

Best practices in apex development

Some of the best practices an apex developer should follow

1. Do not write any soql query within for loop   

2. Use collections especially map to write logic instead of iterating over for loop within for loop, this would save number of statements executed

3. Do not query for data in test class, always create data in test class

4. Use try catch for every dml executed

5. Do not fire dml within for loop

6. Use comments appropriately

7. Static strings should be stored in custom labels

8. Constants, strings likly to be changed should be managed using custom settings

9. Try to see that One object should have only one trigger 

10. No logic with in trigger, move all logic into class

11. Use assert statements in test class, test classes arent meant only for test coverage.

12. Cover positive as well as negative test cases in test class

13. Bulkify trigger, your triggershould work for bulk of a data insert update etc

No comments:

Post a Comment