function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SpoorthySpoorthy 

Apex CPU time limit exceeded is happening only in few records

I am encountering this error only in few cases/records and rest all are working fine and sometimes after few hours the request is going through with out any issue . Do you think that this can happen because of salesforce server is too busy? or we have too many transactions going on in our org simultaneously? what could be the best resolution?
Amit Singh 1Amit Singh 1
Hi Spoorthy,

Apex CPU time limit exceeds error comes into picture when any transaction is executing for more than one minute (60 minutes) synchronously. In order to resolve the error, you can do one of the following things.

1 - Avoid using For loop inside Foor loop with the help of Collection(Map, List, Set)
 
2 - You can limit no of records/objects that are being involved in the whole transaction by setting Limit in your SOQL query.
 
3 - You can use the future method if you want to run any piece of code whenever Salesforce resources are free.
 
4 - You can create Apex Batch and schedule as per your requirement.
 
Visit the below link to know more about the future method.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm

Also, visit the given link.
https://developer.salesforce.com/forums/?id=906F00000009FAOIA2

let me know if this resolves your issue :)

Thanks,
Amit Singh.