3

I have 5 batch classes (implements Database.Batchable). I was able to add all of them in a single schedulable class (implement Schedulable) and schedule it successfully (code below). It worked.

My questions:

  • how many such batch classes can I keep adding to the below schedulable class without errors?
  • Are there any limitations?
  • What issues would I face?

Thoughts please

global class Schedulable_Notifications_ALL implements Schedulable 
{
    global void execute(SchedulableContext sc)
    {
        Batch_Notifications_1 batch1 = new Batch_Notifications_1();
        Batch_Notifications_2 batch2 = new Batch_Notifications_2();
        Batch_Notifications_3 batch3 = new Batch_Notifications_3();
        Batch_Notifications_4 batch4 = new Batch_Notifications_4();
        Batch_Notifications_5 batch5 = new Batch_Notifications_5();

        Database.executeBatch(batch1,10);
        Database.executeBatch(batch2,10);
        Database.executeBatch(batch3,10);
        Database.executeBatch(batch4,10);
        Database.executeBatch(batch5,10);

    }
}
1
  1. how many such batch classes can I keep adding to the below schedulable class without errors? (I think you can add upto 5 only in that way if you want to more you need to add them in flex queue)
  2. Are there any limitations? (5 active batch job limitation.)
  3. What issues would I face? Read this documentation for limits in Batch and issue you may face https://help.salesforce.com/apex/HTViewSolution?id=000176644&language=en_US
  • I just ran with 6 batches in it, it worked fine! – sfdcFanBoy Nov 19 '15 at 5:27
  • wat does active batch mean? – sfdcFanBoy Nov 19 '15 at 6:39
  • means at a time 5 batch executes. once first 5 batch executes next 5 batch executes. At a time we can schedule 100 batch. when first 5 executes rest 95 in queue. like wise all the 100 executes. – Ratan Paul Nov 19 '15 at 6:48
1

Refer to the apex governor limits documentation and you can see that you can schedule up to 100 jobs at the same time, although only 5 jobs can be active at a time, otherwise you'll get an exception.

  • I just ran with 6 batches in it, it worked fine!. Am I missing something? – sfdcFanBoy Nov 19 '15 at 5:37
  • You can check your active batches in Setup>Jobs>Apex Jobs and your scheduled jobs in Setup>Jobs>Scheduled Jobs. As soon as you run your code, you should be able to see 5 active batches and one scheduled batch job. – Santanu Halder Nov 19 '15 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.