Posts

Showing posts from December, 2021

What is Transaction Finalizers ?

Transaction Finalizers in Salesforce Apex are a feature that provides developers with a mechanism to execute logic after a transaction is completed, regardless of whether it's successful or encounters unhandled exceptions. This is particularly useful in the context of Asynchronous Apex, such as future methods, batch jobs, and queueable Apex. You can specify a piece of Apex code to run after the asynchronous operation with transaction finalizers. This flexibility allows you to adapt to various scenarios, benefiting resource cleanup, logging, notifications, or other post-processing operations, giving you a sense of control over your code execution. To use a transaction finalizer, you need to implement the Database. Finalizer interface in your Apex class. The execute method in this interface is invoked after the transaction that the asynchronous code is part of either successfully commits or is rolled back due to an exception Transaction finalizers allow you to attach a post-action s...

Salesforce Platform Event

Image
Platform Events provide a way to deliver secure, scalable, and customizable event notifications within and outside of the Salesforce platform. Platform Events are based on the publish-subscribe model, allowing publishers to broadcast events and subscribers to receive and process those events in real time. Salesforce Event Bus Example: OrderPlaced Platform Event Let's assume you want to create a Platform Event called OrderPlaced__e to represent the event of a new order being placed in your Salesforce org. This event will contain information about the order, such as the order ID, customer name, and total amount. Define the Platform Event Schema: Go to Setup > Platform Events > New Platform Event. Define fields for the event, such as OrderID__c, CustomerName__c, and TotalAmount__c. Publish the Platform Event: You can publish a Platform Event using Apex, Process Builder, Flow, or other methods. Below is an example of publishing an event using Apex. // Publish OrderPlaced event Or...