+ Start a Discussion
vijay bhaskarvijay bhaskar 

can we call a batch apex from another batch apex method

Hi Vijay,

Yes you can call a batch apex from another batch apex .Either in start method or in finish method you can call other batch .You have to decide when you need to call according to your need .

Simply you need to create an instance of the second batch and pass in the Database.execute method either with with batch size or only instance of that class .

Let me know if it helps .

Amit Chaudhary 8Amit Chaudhary 8
Yes you Can call, try to call another batch job in Finish Method like below :-
global class AccountWrecker implements Database.Batchable {
global Database.QueryLocator start(Database.BatchableContext bc) {
  return [select Id, Name from Account];

global void execute(Database.Batchable bc, SObject[] accounts) {
  for (Account[] batch : (Account[]) accounts) {
   for (Account acc : batch) {
    acc.Name += " just got wrecked.";
   update batch;

global void finish(Database.Batchable bc) 
  // can 2nd batch job from here
 AccountWreckerOther obj = new AccountWreckerOther();
 Database.executeBatch(obj ,200);