0

Suppose if i have two batch apex batch jobs 1,2. here i scheduled batch job 1 but not 2. after Batch1 completing immediately Batchjob2 will be executed how to achieve this?

Thanks, Chandra

1
  • Possible duplicate of this post. Please refer to existing posts and search SFSE before posting new questions, as there might already be an existing and approved solution to your problem similar to yours.
    – Mahmood
    Nov 15, 2016 at 11:03

1 Answer 1

1

You can start your second batch by calling it from the finish method of your first batch class. Take a look at the following example:

global database.querylocator start(Database.BatchableContext BC) {
    //start method logic here
}

global void execute(Database.BatchableContext BC, List<sObject> scope) {
    //start method logic here
}

global void finish(Database.BatchableContext BC) {
   //call next batch
   SecondBatch mySecondBatch = new SecondBatch();
   Id batchProcessId = Database.executeBatch(mySecondBatch);
   //finish method logic here
}

Also take a read of both links, some pretty useful info for batch chaining.

  1. Link 1
  2. Link 2
0

You must log in to answer this question.

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