Salesforce Queueable Job is very important for long running data updates. We must notify when particular data update is finished. This feature was not available till winter 2020 release.
Salesforce has introduced transaction finalizer in Spring 2020 release. This will help us adding any post completion logic for Queueable Job.
Finalizers
Finalizer is interface which need to be implemented in a class to add post action. It’s execute method takes FinalizerContext as parameter which will give current executing job detail. So, we can attach the same Finalizer to multiple Queueable jobs and utilize a consistent, common codebase for post-async actions. Like in case of error send email to IT Ops team etc.
We can attached finalizer using System.attachFinalizer.
System.attachFinalizer(emailFinalizer);
SendEmailFinalizer can be used for all queueable jobs in org. Let us see how to use above Finalizer class in queueable job.
Summary:
Finalizers is new feature which will help in adding post completion logic for queueable jobs.
Reference: