You need to sign in to do that
Don't have an account?
alaschgari
How to implement a batch queue?
Hey folks,
My customer has an org where batches are started regularly throughout the day. In order to prevent getting the "5 batches limit" error, my primary solution would be to implement something like a batch queue. Is this a) the best solution and b) if yes, how can I implement it?
Cheers
Josh :-)
Hi Josh,
You need to create a schedulable class which would invok multiple batch class one after another.The sample code is below :-
//declaration of scheduler class
global class ScheduleMultipleBatchJobs implements schedulable
{
//method to implement Apex schedulers
global void execute(SchedulableContext ct)
{
BatchDeletion BD = new BatchDeletion();
Database.executebatch(BD); // Invoking first batch
UpdateAccountFields UP = new UpdateAccountFields();
Database.executebatch(UP); //invoking second batch
}
}
Here,I am scheduling two batch classes (BatchDeletion and UpdateAccountFields) in a sinle schedulable class,the 2nd batch class woul start after the finish of first and so on,hence you would not be getting concurrent batch error as the the batches would run after another.