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

  • 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 '16 at 11:03
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
| improve this answer | |

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.