Monday, July 7, 2014

How to understand "Apex CPU time limit exceeded"

Ok so have developed that one big data driven page with all the logic but when the data hits some thrashold point you receive this error: Apex CPU time limit exceeded. This is a common problem when your page is having very complex logic that the apex run time compiler cannot finish in a given synchronous cycle. In simple words the error is due to the logic to be very complex to be completed in CPU limit time.
Salesforce has 10000 millisecond for synchronous and 60000 millisecond for asynchronous.

There are few way we can resolve this error :

  1. Limit the data - if you know that after a certain amount of data this error occurs then provide a limit to your SOQL.
  2. Reduce the number to for, while etc loops - as number to iteration is lower the CPU compiles faster.
  3. Use Map and Sets. 

No comments:

Post a Comment