Posts

Showing posts with the label Exception Handling

LinkedIn

Salesforce Record Triggered Flows - Create custom error messages

Image
  1. Introduction As part of Winter 24 release, Salesforce released this much-awaited flow feature by which we can fire custom error messages to users as part of record-triggered flows. This feature is available as part of both before and after save record triggered flows. We can add error messages to a specific field or at the page level. Let us see 2 use cases to demonstrate this feature. 2. Use case 1 - Before Save Flows Scenario - When an Account is getting deactivated and if there are any active Contacts under that Account, deactivation should be failed with a custom error message. Implementation steps: 1. Create an isActive checkbox in contact 2. Create a before record triggered flow in Account to check for active contacts when Account Active value becomes false: Add entry criteria as Active field update:  Now fetch active contacts under that Account: Now add a decision element to check if the count >0 if a contact exists add custom error we can see Custom Error avail...

Transaction Finalizers for Asynchronous Apex Jobs

Image
Transaction Finalizers are Generally Available from Summer 21 release. Let us see the features and how to implement Transaction finalizers in this blog post. 1. What is Transaction finalizers? The Transaction Finalizers feature enables you to attach actions, using the  System.Finalizer  interface, to asynchronous Apex jobs that uses the Queueable framework. The logic associated with Finalizer implementation will be executed once the asynchronous execution finishes.  2. Methods available for Finalizer Interface We can get below details of the executed job process in the finalizer Implementation: 3. Features of Transaction Finalizers 4. Implementation Details Use Case We want to execute 2 operations: 1. When ever a new contact is getting created/updated with Country field value, parent Account's Account country field should be appended with new country If Account ABC has 2 contact - Contact X with country India and Contact Y with country France, the Account Country in Accou...

Batch Apex - Better Exception Logging using Standard Platform Event - BatchApexErrorEvent

Image
BatchApexErrorEvent is a standard platform event introduced by Salesforce as part of API version 44.0. This mainly helps us to get the details of unhandled exceptions that happened from Batch Apex. To fire exception details to BatchApexErrorEvent, Batch Apex should implement  Database.RaisePlatformEvents interface. Let us cover below in detail: 1. BatchApexErrorEvent Details BatchApexErrorEvent holds below details: Let us implement a batch apex and see how BatchApexErrorEvent is helpful for tracking unhandled exceptions. 2. Sample Batch Apex Scenario Both Account and Contact has a field called Active__c which contains 2 values - Yes, No. When a parent Account is getting deactivated,ie Active=No, we need to mark all child contact's Active also as No. Batch Apex Logic Below Class is implemented to solve this. You can see that this class has implemented  Database.RaisePlatformEvents interface. public with sharing class Batch_ContactDeactivation implements Database.Batchable<...

Screen Flows - Exception Handling & Logging - Custom Platform Events Vs Flow Execution Error Event

Image
In the previous post , we saw how to handle and log exceptions in auto-launched flows. In this post let us see Exception handling and logging for screen flows. For this let us use the below Use case: Object - Account Flow Functionality -  If the Account type(picklist with values End-User, Partner) is Partner Account – Display a screen to enter additional details by user and based on entered values, decide Account Partnership level(picklist) as Diamond, Gold or Silver. This screen flow  will be added to Account record page. Below is the Screen flow which implements this. Scenario - 1 - Partnership Level Updated Successfully Add this flow to Account Record page like shown below: We can make this conditionally visible on the record page by adding component visibility criteria so that screen will be visible only if Account Type is Partner: Now let us create an Account  - Account ABC with below details: Name - Account ABC Active - True Account Type - Partner And we can see tha...