3

We are experiencing performance issues on our org and over the years the size of the org (data + bus logic components like workflows, triggers, fields etc..) have grown rapidly and exponentially.

We are planning to review the trigger code manually, could you please suggest:

  1. If there are any trigger practices / or link to the triggers best practices document
  2. What are the TOP 5 major coding components that we need to look for while trying to improve the trigger code.

3 Answers 3

1

You may look into following links for some of the best practices https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bestpract.htm http://wiki.developerforce.com/page/Apex_Code_Best_Practices

1

Over the years of working with Salesforce.com my team and I used a different trigger pattern and we found that each project requires own trigger template thus it's hard to suggest something concrete to you, but usually we use the following link during our work on design a trigger template for new project and mix them:

as well as links which has been provided by @codebandit

0

There is a lot to talk about and depending on your case there might be different solutions how to improve and refactor.

What I'd suggest first is to map out all triggers and workflows against each object and identify the dependencies. Then start looking at merging code and moving out code from triggers to classes and static methods. For each object I would create 1 trigger only and each piece of logic would be in a separate method which will be called from the trigger. That way you get very good visibility of the order of execution of things in your trigger.

Things to look out for and must do's:

1) SOQL queries in for loops

2) DML statements in for loops

3) Recursive triggers (calling each other X times) - you need to make sure each trigger is only called once and implement some mechanism to prevent from recursion

4) Use maps and avoid nested for/do-while loops

5) Comments, lots of comments

I am sure there is a lot more that I've missed and can be found in the documentation for apex triggers best practices and someone might have a different approach when it comes to complex trigger logic. Hope this helps you get started.

1
  • Thanks for your reply, this was very useful.. I am planning to take the list of all workflows, its rule criteria, evaluation criteria, Action (I need to take this only for 3 objects) but there are plenty of workflows. Is there a way to query or app exchange app to get this list..Then i am planning to compare it against the triggers and eliminate some workflows.
    – user5352
    Commented Apr 7, 2014 at 7:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .