function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
marcobmarcob 

call Batch from Batch execute method

Hi,

is it possible to call a Batch Apex from an execute method of another Batch Apex? I've read in another post that it won't work from a finish method, but maybe it might work from an execute method?

Thx!

Marco

Best Answer chosen by Admin (Salesforce Developers) 
Jerun JoseJerun Jose

batch apex cannot call another batch apex. End of story.

So no, your execute method cannot kick off another batch process.
Its against the rules . :P

All Answers

Leon MorockiLeon Morocki

This most probably won't work either. What you can do is try to schedule another batch execution (for instance to run in the next 5 seconds) from the finish method of the first batch.

marcobmarcob

I've thought about that, but want to avoid it.

 

Basically, i have a batch job but run into heap size problems. So, i want to cut my job into smaller chunks. If i use the scheduler, i need to go through a lot of hassle to provide the proper selections to the next batch job. It is much easier to use a straightforward loop, and run it over and over for the next 100 records, until i reach the end of my list.

 

I think i will create a loop in which i fire off batch jobs, and accept that i see a huge number of apex jobs in the console. And in the last one, i will put things together to one total file (my batch job creates an xml file).

 

Marco

 

Jerun JoseJerun Jose

batch apex cannot call another batch apex. End of story.

So no, your execute method cannot kick off another batch process.
Its against the rules . :P

This was selected as the best answer
marcobmarcob

yeah, i read that a few hours ago in the apex guide, so i'm now in the middle of a re-design, so we don't have to cut up our process. 

thanks for the feedback!

Marco