Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.
share|improve this question

Over the years of working with 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

share|improve this answer

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.

share|improve this answer
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 Apr 7 '14 at 7:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.