Attach Actions to Asynchronous Apex Jobs Using Transaction Finalizers (Beta)
Where: This change applies to Lightning Experience and Salesforce Classic. To use this beta feature, it isn’t necessary to enable the 'Transaction Finalizers' feature in scratch orgs. The Transaction Finalizers feature isn’t restricted to scratch orgs, can be used in production orgs and sandboxes, and can be included in managed packages.
- getAsyncApexJobId method: Returns the ID of the Queueable job for which this finalizer is defined.
- getRequestId method: Returns the request ID shared by both the finalizer execution and the Queueable job to which the finalizer is attached. This shared ID helps in filtering logs of a Queueable job and its attached finalizer.
- getResult method: Returns the System.ParentJobResult enum, which represents the result of the parent asynchronous Apex Queueable job to which the finalizer is attached. Valid values for the enum are SUCCESS, and UNHANDLED_EXCEPTION.
- getException method: Returns the exception with which the Queueable job failed when getResult is UNHANDLED_EXCEPTION, null otherwise.
To attach actions to your Queueable jobs, you must implement the FinalizerContext interface. Only one finalizer instance can be attached to any Queueable job. You can enqueue a single asynchronous Apex job (Queueable, future, or batch) in the finalizer’s implementation of the execute method. Callouts are allowed in finalizer implementations.
For more information on implementing Transaction Finalizers, including examples, see Transaction Finalizers (Beta) in Apex Developer Guide.