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
alaschgarialaschgari 

Batch: Attempted to schedule too many concurrent batch jobs in this org

Hey folks,

 

What is the best solution to prevent this error message: 

System.LimitException: Attempted to schedule too many concurrent batch jobs in this org (limit is 5).

 

Cheers

Josh :-)

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

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 would 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.