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:

Dhanik Lal Sahni is a Salesforce Solution Architect, Independent Consultant, and the founder of SalesforceCodex.com. With nearly two decades of IT experience and extensive expertise in Salesforce architecture, he helps startups and enterprises design scalable, secure, and high-performance CRM solutions using Sales Cloud, Service Cloud, Experience Cloud, Data Cloud, Apex, Lightning Web Components (LWC), and enterprise integration patterns.
Through SalesforceCodex, he shares practical tutorials, real-world implementation guides, enterprise architecture best practices, and interview preparation resources for Salesforce Developers, Architects, and Administrators.
Learn more about his Salesforce consulting and freelance services at dhaniksahni.com.
