February 21, 2014

System.LimitException: Apex CPU time limit exceeded

The CPU Time that was introduced in Winter '14 release. Prior to Winter' 14, Salesforce had Script limit.

For Synchronous call, it is 10,000ms.

For the Asynchronous call, it is 60,000ms.

What contributes to CPU Time Limit:
1. Debug logs statements.
2. Using Describe information ( example is Account.soObjectType.getDescribe ) inside the for loop.

1. Use Limits getCPUTime() to debug in a sandbox.

Workarounds or Solutions:
1. Use @future, Queueable Interface, or Asynchronous Apex Triggers.
2. Avoid using several debug log statements.
3. Bulkify the triggers.
4. Avoid multiple for loops.
5. Use Singleton pattern.
6. Use Double data type over Decimal for calculations.

No comments:

Post a Comment