Attach Actions to Asynchronous Apex Jobs Using Transaction Finalizers (Pilot)
Where: This change applies to Lightning Experience and Salesforce Classic only in scratch orgs that have enabled the feature during org creation. Because finalizers are currently in pilot and are available only in scratch orgs, do not attempt to package finalizers.
- 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. The enum takes these values: SUCCESS, UNHANDLED_EXCEPTION.
- getException method: Returns the exception with which the queueable job failed when getResult is UNHANDLED_EXCEPTION, null otherwise.
- Define a class that implements the System.FinalizerContext interface.
- Attach a finalizer within a queueable job’s execute method. To attach the finalizer, invoke the System.attachFinalizer method, using as argument the instantiated class that implements the System.FinalizerContext interface.
For more information on Transaction Finalizers, including examples, see Transaction Finalizers (Pilot) in Apex Developer Guide.