I scheduled an apex job to run daily at midnight but noticed that the job failed due to the Apex CPU time limit exceeded error. The code works in my developer sandbox but not in production. I'm wondering if it is because of something in my SOQL query, but unclear on where the culprit would be. The query only returns about 500 records in production. Any help is appreciated- here is my class:
global without sharing class UnassignAccountsDueToInactivity implements Schedulable {
global void execute(SchedulableContext ctx) {
List<Account> acctList = [SELECT Id, Name, OwnerId
FROM Account
WHERE (OwnerProfileName__c LIKE '%AE%' OR OwnerProfileName__c LIKE '%SDR%') AND
(Current_Customer__c != 'Current Customer A' AND Current_Customer__c != 'Current Customer B' AND Current_Customer__c != 'Current Customer C') AND
Number_of_Open_Opportunities__c <= 0 AND
DaysSinceLastActivity__c >= 30 AND
DaysSinceLastOwnerChangeDate__c >= 7];
if(!acctList.isEmpty()){
for(Account acc : acctList){
acc.DisqualifiedReason__c = 'No response';
acc.OwnerId = '000000000000000';
}
update acctList;
}
}
}
QueryException
. While efficiency could be enhanced here, even the most inefficient of queries wouldn't take 60 seconds to run (the async CPU time limit). The root of the problem must be somewhere else.