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
Ranjith DevRanjith Dev 

Apex cpu time limit exceeded for schedule job

Hi 

In my Client org iam facing an issue is 'Apex cpu time limit exceeded' for Schedule job. Can you please help me on this.

Thank you
SwethaSwetha (Salesforce Developers) 
HI Ranjith,
1. This error generally occurs if transactions consume too much CPU time. Salesforce has a timeout limit for transactions based on CPU usage. If transactions consume too much CPU time, Salesforce shut them down as a long-running transaction.

2. To fix the issue, you need to optimize the code involved following the best practices described in the below articles.

>> https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1
>> https://developer.salesforce.com/page/Apex_Code_Best_Practices

3. Please use the following limit methods in your code to debug the amount of CPU time currently used in the transaction:

getCpuTime()
Returns the CPU time (in milliseconds) accumulated on the Salesforce servers in the current transaction.

getLimitCpuTime()
Returns the time limit (in milliseconds) of CPU usage in the current transaction.

Related:https://salesforce.stackexchange.com/questions/295666/apex-scheduler-with-cpu-time-limit-problem
https://salesforce.stackexchange.com/questions/102012/apex-cpu-time-limit-exceeded-error-in-scheduler-class?rq=1

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you