You might get this Error fairly frequently when developing complex Apex Triggers. In this article, we will look at the causes and possible solutions to address the issue.
What?
This error message typically means that the Apex Trigger is taking too long to execute. The maximum CPU time for a trigger is 10,000 milliseconds or 10 seconds. Note that the time taken for DML and SOQL operations does not fall into this category.Why?
When you get this error, it DOES NOT mean that you have too many DML operations or large SOQL queries. Rather, it means that there is a problem in the way you handle the result of those operations.Things to check
- Try using a MAP instead of a LIST. A MAP is always much efficient to use.
- Try to avoid iterations or FOR loops wherever possible.
- Check your nested FOR Loops. This is one MAJOR area which consume too much time. Try to minimize the iterations.