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
SFDC ROCKSFDC ROCK 

one batch apex to another batch apex

we can not call one asynchronous process to another asynchronous process but how can we call from one batch to another batch since batch is also asynchronous process?
Best Answer chosen by SFDC ROCK
Khan AnasKhan Anas (Salesforce Developers) 
Hi Subodh,

Greetings to you!

There's no rule that says that "asynchronous cannot call asynchronous". There are specific rules in place, such as "future cannot call future". A Queueable can call another Queueable, a Batchable can call another Batchable in the finish method, and Scheduleable methods can call Batchable and Queueable methods. There are usually lesser limits allowed for asynchronous contexts (e.g. a Queueable can call only one Queueable, while a normal synchronous transaction can call 50 of them).

Reference: https://salesforce.stackexchange.com/questions/204896/calling-async-from-async-process

To call another batch class from a batch class: 
1. Call another batch class in the finish method as execute method is called many times but Start and finish method only once.
2. So once your main batch is completed and the finish method is called and then it will call another batch.

Please refer to the below link which might help you further:

https://www.biswajeetsamal.com/blog/invoke-batch-apex-from-another-batch-apex/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Subodh,

Greetings to you!

There's no rule that says that "asynchronous cannot call asynchronous". There are specific rules in place, such as "future cannot call future". A Queueable can call another Queueable, a Batchable can call another Batchable in the finish method, and Scheduleable methods can call Batchable and Queueable methods. There are usually lesser limits allowed for asynchronous contexts (e.g. a Queueable can call only one Queueable, while a normal synchronous transaction can call 50 of them).

Reference: https://salesforce.stackexchange.com/questions/204896/calling-async-from-async-process

To call another batch class from a batch class: 
1. Call another batch class in the finish method as execute method is called many times but Start and finish method only once.
2. So once your main batch is completed and the finish method is called and then it will call another batch.

Please refer to the below link which might help you further:

https://www.biswajeetsamal.com/blog/invoke-batch-apex-from-another-batch-apex/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
SFDC ROCKSFDC ROCK
Thank you @Anas for such a good explanation.