How to avoid concurrent batch execution in Salesforce?

Sample Code:

if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')] < 1]){
} else {
   Schedulable_Class sc = new Schedulable_Class();
   Datetime dat =; // This is for 30 mins delay
   String timeForScheduler = dat.format('s m H d M \'?\' yyyy');
   Id scheduleId = System.Schedule('Trying again' + timeForScheduler, timeForScheduler,sc);


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit