Skip to main content

Sneak Peek: Handle Record Delete triggers using Flow Automations

Traditionally, within Salesforce platform, only Apex triggers were equipped to handle record delete events. For any custom handling of delete actions, one had to create and maintain Apex code. Not to mention, be mindful of the best practices of handling deletions in bulk and displaying error messages.

Salesforce flows have been graduated to now handle on delete events for objects within Salesforce. So, now you can create a flow which gets triggered on record delete.

Step by Step Guide

Let's take a sample scenario (probably most used). Let's say you want to restrict any user to delete an Account of type Customer. Following are the steps to create flow

Step 1 : Create a flow of type Record Triggered Flow



Step 2 : Set Entry Criteria

  1. Set Trigger to A record is deleted
  2. Set Entry conditions to qualify only active customer accounts

Step 3 : Add new Custom Error

Add new element attached to Start element and select Custom Error element from the list

Step 4 : Setup Error Message

Add error message to the component and configure where error message should be displayed


Step 5 : Save and activate flow

(You probably don't need a screenshot for this)

Step 6 : Test and verify flow works



Tips

Error - while trying to deploy flow metadata

While retrieving metadata for flow, do ensure that you have correct API version, dependent on the components/features used within flow. For instance, if you create a flow which uses a Custom Error element but retrieve metadata using API version 56.0, you would notice Custom Error element metadata will be missing within flow metadata. 

Solution

Re-retrieve flow (example uses flow named test) metadata using API version 59.0 or above


sfdx force:source:retrieve -m Flow:test -a 59.0


Comments

Popular posts from this blog

Quick Tips: Sort Pipeline by Sales stages with Salesforce Tableau CRM (Einstein Analytics)

Quick Tips: Sort Pipeline by Sales stages with Salesforce CRM Analytics (aka Tableau CRM) Problem Statement While working on a recent change, we realized (a bit late) that the sales pipeline view shows sales stages in incorrect order. Ideally, you would want the pipeline view to reflect the stage in the same sequence as the sales process (for example Prospect, Propose, Negotiate, Close). Sales Path Sales Pipeline Initial SAQL q = load "opportunities" ; q = group q by 'StageName' ; q = foreach q generate 'StageName' as 'StageName' ,      sum ( 'Amount' ) as 'sum_Amount' ; q = order q by 'StageName' asc ; q = limit q 2000 ; Solution Approach Approach 1: Augment a field within the Opportunity dataset (CRM Analytics) to generate a new column for the Sales stage sequence This approach would be faster to deliver and has comparatively less change. However, as sales stages are changed/ updated it can result in the Tableau CRM da...

Quick Tips: Salesforce default Images

Well, I'm sure a lot of you still rely on using out of the box salesforce images for displaying quick icons within formula fields or even using them within your Visualforce pages. Lately, I realized that a lot of earlier resources are no longer accessible, so I tried to quickly extract all images from Salesforce CSS files and provide a quick reference here. Please note, I've referenced all images from SF servers directly, so if anything changes, the image should stop rendering here. As these images are completely controlled by Salesforce, and in case they change anything, it might lead to image not being accessible. Image path Image /img/samples/flag_green.gif /img/samples/flag_green.gif /img/samples/flag_red.gif /img/samples/color_red.gif /img/samples/color_yellow.gif /img/samples/color_green.gif /img/samples/light_green.gif /img/samples/light_yellow.gif /img/samples/light_red.gif /img/samples/stars_100.gif /img/samples/stars_200.gif /img/samples/stars_300....

Lightning: Generate PDF within Lightning Experience with Salesforce Data

Some time back I posted a solution to generate PDF from Lightning components using in-memory data. Post url: http://www.vermanshul.com/2017/07/lightning-generate-pdf-from-lightning.html It was developed for a specific scenario, wherein we need to generate PDF where: User interface is Salesforce classic Initiated via Lightning Component Data doesn't exist within Salesforce and is completely in-memory As complex and tricky this situation was, we did end up finding a stable and equally tricky solution. However, I realize that there are still lack of solutions (or maybe my search skills are downgrading) to generate and automatically download PDF document from Lightning Experience, without using any lightning components, wherein data exists within Salesforce. You can use the earlier solution in that case, but it will be an overkill. There are various solutions available to generate PDF from javascript. But, I still think the plain old method of converting HTML to PDF (via...