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
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communitySuppose 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
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.