What is the best possible way to check record that match with my criteria and update it? i have try using scheduled jobs that run every 15 minutes but sometimes it run sometimes it doesn't run. it seems it will run depend on available resource
Here scheduled apex code
global class CallQueueLeadChecker implements Schedulable {
Datetime dtNow = system.now();
global void execute(SchedulableContext SC){
checkLead();
}
public void checkLead(){
List<Lead> leadList = [SELECT Id,Active_Call_Queue2__c FROM Lead WHERE Active_Call_Queue2__c = FALSE AND No_Call_Queue__c = FALSE AND (NOT Phone LIKE '%wrong%') AND (NOT Phone LIKE '%invalid%') AND (NOT MobilePhone LIKE '%wrong%') AND (NOT MobilePhone LIKE '%invalid%') AND (Phone !=null OR MobilePhone !=null) AND (Status='Open' OR Status = 'Contacted') AND Picked_By__c=null AND Is_Picked__c = FALSE AND (Last_Open_Timestamp_Formula__c <: dtNow OR Last_Open_Timestamp_Formula__c = NULL) ORDER BY Hubspot_Score__c DESC NULLS LAST LIMIT 200];
for(Lead l : leadList){
l.Active_Call_Queue2__c = TRUE;
}
update leadList;
}
}
These are the cron jobs to run schedule apex every 15 minutes
System.schedule('Call Queue Checker 0', '0 0 * * * ?', new CallQueueLeadChecker());
System.schedule('Call Queue Checker 15', '0 15 * * * ?', new CallQueueLeadChecker());
System.schedule('Call Queue Checker 30', '0 30 * * * ?', new CallQueueLeadChecker());
System.schedule('Call Queue Checker 45', '0 45 * * * ?', new CallQueueLeadChecker());
Regards, Brian