Best Practices for writing Apex Triggers
1) Follow only one trigger for each object.
2) Logicless Trigger, which means create a helper method to keep all logic and finally call that helper class and method in the trigger.
3) Bulkify helper class or trigger to avoid governor limits.
4) Avoid using SOQL and DML within for loop.
5) Use collections like list, set and map to store on large set of data.
6) Use streamline queries and efficient for loop to process large set of data.
7) Use addError() method to show error message upon validation.
8) Use try and catch block to handle exception and throw error messages.
1) Follow only one trigger for each object.
2) Logicless Trigger, which means create a helper method to keep all logic and finally call that helper class and method in the trigger.
3) Bulkify helper class or trigger to avoid governor limits.
4) Avoid using SOQL and DML within for loop.
5) Use collections like list, set and map to store on large set of data.
6) Use streamline queries and efficient for loop to process large set of data.
7) Use addError() method to show error message upon validation.
8) Use try and catch block to handle exception and throw error messages.
No comments:
Post a Comment