[SalesForce] Batch Apex Chaining Limits

I have seen Apex Batch Job Chaining Limits, but my questions is little bit different so still wanted to confirm. I was looking to chain 3 batch classes.

Below would be number of batch classes.

  1. BatchCls1
  2. BatchCls2
  3. BatchCls3

I want to call Batch 1 will be called from ScheduleApex class and BatchCls2 will be called from BatchCls1 finish method and BatchCls3 will be called from BatchCls2 finish method.

In above case would there be any stack depth issue or any other limitations that i should keep in mind as I'm going 3 levels deep?

Note: I don't have any code yet as I'm still in the design phase and wanted see foreseeable limitations

Best Answer

By "stack depth" I presume you mean "chain length"; each start/execute/finish runs in its own transaction and so has its own stack.

I know of no absolute limit: chaining is very kind to the platform because things run in a sequence rather than in parallel. But worth some approximate calculations to see if you will run anywhere near this limit recognizing that each start/execute/finish counts as one of these:

Description
The maximum number of asynchronous Apex method executions (batch Apex, future methods, Queueable Apex, and scheduled Apex) per a 24-hour period

Limit
250,000 or the number of user licenses in your org multiplied by 200, whichever is greater

PS

I'd forgotten about the limit in tests that sfdcfox comments about. One way around that is shown in Testing a Database.Batchable implementation.

Related Topic