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,50);           

        BatchClassB b1 = new BatchClassB();
        ID batchprocessidA = Database.executeBatch(b1,50);
    }

}

Will this actually work?

1 Answer 1

1
global class Scheduler_class implements Schedulable{

    global void execute(SchedulableContext sc) {

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

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

It will work without any issue. But make sure that you are not going to hit maximum batch execution queue/run limit, it is 5.

0

You must log in to answer this question.

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