The Transaction Finalizers feature enables you to attach actions, using the System.Finalizer interface, to asynchronous Apex jobs that use the Queueable framework. A specific use case is to design recovery actions when a Queueable job fails.
Sample Use Cases:
1. Retry in FinalizerContext if the queueable job fails
2. Add error log record in FinalizerContext to report on failures
Sample Class:
public class SampleClass implements Finalizer, Queueable {
public void execute( QueueableContext ctx ) {
}
public void execute( FinalizerContext ctx ) {
String parentJobId = ” + ctx.getAsyncApexJobId();
if ( ctx.getResult() == ParentJobResult.SUCCESS) {
System.debug(‘Parent queueable job [‘ + parentJobId + ‘] completed successfully.’);
} else {
System.debug( ‘Parent queueable job [‘ + parentJobId + ‘] failed due to unhandled exception: ‘ + ctx.getException().getMessage() );
}
}
}
To pass data through variable to the Finalizer, check the following: