1

I was just wondering is it possible to class executeBatch method of two different Batchable classes inside the execute method of a Schedule class. For example;

global class BatchClassA implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        //query goes here;
    }

    global void execute(Database.BatchableContext BC, List<Child__c> scope)
    {
        //execution goes here
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

global class BatchClassB implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        //query goes here;
    }

    global void execute(Database.BatchableContext BC, List<Child__c> scope)
    {
        //execution goes here
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

global class Scheduler_class implements Schedulable{

    global void execute(SchedulableContext sc) {

        BatchClassA b1 = new BatchClassA();
        ID batchprocessidA = Database.executeBatch(b1);           

        BatchClassB b2 = new BatchClassB();
        ID batchprocessidA = Database.executeBatch(b2);
    }

}

If there are more than 2 Million records(both batch class have to handle more than 2 million records in one go individually), will this work? What about the governor limits?

or the scheduler class should be different for both of the batch classes?

3
  • You don't need to use global...
    – Adrian Larson
    Commented Apr 19, 2017 at 16:52
  • are you talking about scheduler class?
    – Traveller
    Commented Apr 19, 2017 at 16:53
  • 1
    Any of them. You never need to use the global modifier unless you are building an API on the platform (webservice or ApexRest) or if you are developing a managed package. You are doing neither in this case.
    – Adrian Larson
    Commented Apr 19, 2017 at 16:56

1 Answer 1

1

The batch doesn't even start executing until after the Schedulable's execute method terminates successfully. You may run in to governor limits if you're near the global limit for held batches (currently 100), but you shouldn't ordinarily run into transaction governor limits. Each start method of each Batchable class will get its own transaction limits (10 minutes, 50,000,000 records, etc).

2
  • I suppose, in this case count should be 2 only out of 100, right? and each batch will handle 50 million records separatly?
    – Traveller
    Commented Apr 19, 2017 at 16:52
  • @AnkurGupta Yes, but if you were already at 99 held jobs, you'd run into the governor limit.
    – sfdcfox
    Commented Apr 19, 2017 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .