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
Anuj Thakur 4Anuj Thakur 4 

we know that we can not call a future from a batch or from another future but why?

Hi All,
1. we know that we can not call a future from a batch or from another future because both are asynchronous. But we can call a batch from another        batch even batchs also asynchronous. I googled it but did not get any proper answer. could you please suggest your views ont his.
2. we can call a batch from another batch only from start or finish method but not from execute method, why?
Any response would be appriciated.
Thanks,
Anuj
 
Best Answer chosen by Anuj Thakur 4
Nandigam RajeshNandigam Rajesh
Hi Anuj,
1) Usually we are not supposed to give a call from the asynchronous to asynchronous because we don't know when it get worked (executed when the source is available only). In terms of batch class we can do this only in the finish method, there only we can understand the another batch can execute after completion of one batch this is the exceptional case.
2) Can call batch class to batch class in only finish not possible​ in the start method. If we call the 2nd batch class in the execute method we may have a possibility to call the second batch once the some group of the records has been processed that would not be much effective for whole process.


Regards |Rajesh | Technician

All Answers

Nandigam RajeshNandigam Rajesh
Hi Anuj,
1) Usually we are not supposed to give a call from the asynchronous to asynchronous because we don't know when it get worked (executed when the source is available only). In terms of batch class we can do this only in the finish method, there only we can understand the another batch can execute after completion of one batch this is the exceptional case.
2) Can call batch class to batch class in only finish not possible​ in the start method. If we call the 2nd batch class in the execute method we may have a possibility to call the second batch once the some group of the records has been processed that would not be much effective for whole process.


Regards |Rajesh | Technician
This was selected as the best answer
Anuj Thakur 4Anuj Thakur 4
hi Rajesh,

Thanks for your quick response.
Refards,
Anuj