What is the limit on Queueable jobs enqueued from a Transaction Finalizer's finalize method in Salesforce?
0 reputation · 17 Mar 2021, 09:18 UTC
0 reputation · 17 Mar 2021, 09:18 UTC
When a Queueable class implements the Finalizer interface, the finalize method runs after the Queueable job completes and can enqueue additional Queueable jobs. It is not documented whether these enqueues are subject to the same per‑transaction limit that applies to Queueable jobs added directly from synchronous code or from the Queueable execute method.
Understanding this behavior is important for designing reliable chaining patterns that avoid unexpectedly hitting the Queueable job limit, especially when processing large data sets across multiple asynchronous steps.
Does the finalize method execute in the same transaction as the original Queueable job? If it runs in a separate transaction, does it inherit its own Queueable job limit? What is the practical impact on chaining Queueable jobs via finalizers when aiming to stay within governor limits?
35275 reputation · 17 Mar 2021, 12:16 UTC
The finalize method of a Queueable class that implements Finalizer runs in a separate transaction after the original Queueable's execute method finishes. Each transaction is governed by the same Queueable job limit of 50 jobs, so you can enqueue up to 50 Queueable jobs from within finalize.
EXECUTION_STARTED block in debug logs).LimitException: Too many queueable jobs added to the queue: 51.Because the finalize method is treated as a new asynchronous context, it does not inherit any remaining Queueable job allowance from the original transaction; it starts with a fresh limit of 50.
execute, do minimal work.finalize, enqueue 50 simple Queueable jobs that do nothing.System.enqueueJob in anonymous Apex and check that all 50 jobs are queued successfully.EXECUTION_STARTED/EXECUTION_FINISHED blocks around the finalize method to confirm a new transaction.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.