Are you creating schedule class for each batch class if you need to schedule that?
If yes, stop doing like that and start creating a universal (common scheduler class) like below and use it instead of creating multiple schedules.
Step 1:
Create a universal scheduler class
If yes, stop doing like that and start creating a universal (common scheduler class) like below and use it instead of creating multiple schedules.
Step 1:
Create a universal scheduler class
- public class UniversalScheduler implements Schedulable{
- public Database.Batchable<SObject> batchClassName{get;set;}
- public Integer batchScopeSize{get;set;} {batchScopeSize = 200;}
- public void execute(SchedulableContext sc) {
- Database.executebatch(batchClass, batchSize);
- }
- }
Step 2:
Let say, You have two batch classes and you want to schedule, then schedule batch class like below using UniversalScheduler class
Batch Class 1:
- AccountBatchProcess accBatch = new AccountBatchProcess(); // Batch Class Name
- UniversalScheduler scheduler = new UniversalScheduler();
- scheduler.batchClass = accBatch;
- scheduler.batchSize = 100;
- String sch = '0 45 0/1 1/1 * ? *';
- System.schedule('Account Batch Process Scheduler', sch, scheduler);
Batch Class 2:
- ContactBatchProcess cntBatch = new ContactBatchProcess(); // Batch Class Name
- UniversalScheduler scheduler = new UniversalScheduler();
- scheduler.batchClass = cntBatch;
- scheduler.batchSize = 500;
- String sch = '0 45 0/1 1/1 * ? *';
- System.schedule('Contact Batch Process Scheduler', sch, scheduler);