Automatically Delete Records Using Salesforce Flows

When we are doing business with a customer, we create an account and mark it as Active. Also, when we stop working with that customer, the user sets that account as deactive.

The requirement is that whenever a user marks an Account as not active and saves the record, Salesforce should automatically delete that Account.

A Record-Triggered Flow will check if Account_Active__c is set to False. If it is False, the Flow will automatically delete the Account record without any manual work.

In this article, we will learn how to automatically delete records using Salesforce flows, using real-time scenarios and step-by-step explanations.

Delete Records Using Salesforce Flows

I was assigned the task: if we get any opportunity in the “Close Lost” stage, it should be deleted automatically.

To create this process automatically, we can set up a record trigger flow that triggers when the opportunity stage changes to Close Lost, and then the record is deleted.

This will be useful to the organization for deleting records that do not meet business criteria or are not required.

Create Record Trigger Flows in Salesforce

Using the above scenario and the following steps, we can delete records using Salesforce Flow.

  1. Log in to Salesforce Org. -> Click on the Setup -> Home Tab -> In the Quick Find Box, Search for Flows. You will see an option under Process Automation -> Click on Flows.
Delete Record Using Flow in Salesforce
  1. Then, click on the New Flow button to create a new flow.
Delete Record in Salesforce Flow
  1. We know the record trigger flow launches when the record is created, updated, or deleted.
    • When the opportunity stage is updated or changed to “Close Lost,” the record will be deleted.
    • To do that, we have to select the Record Trigger flow and click on the Create button.
Delete Record using Salesforce Flow
  1. As we click on the create button, we will see the flow canvas. In our scenario, the flow should trigger when we update the Opportunity record, so I selected the Opportunity in the Object field.
    • In Configure Trigger, I have selected A Record is Updated because when we update the opportunity stage to “Close Lost”, the record, the flow should trigger.
How to Delete Record in Salesforce Flow
  1. Then, we have to ‘Set Entry Conditions‘, and in the Condition Requirement option, select All Conditions Are Met (AND) because the following condition must meet the criteria.
    • Our triggering condition is that StageName equals “Close Lost.” Then, the trigger should fire.
    • Then we need to select “Every time a record is updated and meets the condition requirements.” When you select this option, the flow will trigger every time you update the record.
    • We are going to update the opportunity records and want to delete those records whose opportunity stage is ‘close lost’. We need to select ‘Optimize the Flow for Action and Related Records‘.
How to Delete Record Using Flow in Salesforce
  1. Now, we need to add the Delete Record element. To ‘Add Element‘, click on the + plus icon, and then under the Data component, you can see Delete Record. Click on it.
    • When we click Delete Records, we have to enter the Label that will appear on the flow canvas. The API Name will automatically populate.
  1. Then, we need to select How to Find Record to Delete. Here, we need to provide the current RecordID to the Opportunity ID.
    • For that, select Specify Conditions, and in the Object field, select Opportunity object.
    • Then, specify the current RecordID for the Opportunity ID.
How to Delete Record using Salesforce Flow
  1. After setting up all labels and conditions, save the flow first. You can see the Save button. Click it, then click the Debug button.
    • Then click on the Activate button; always remember to debug the flow before activating it. It’s good practice to use flow.
How to Delete Records using Flow in Salesforce
  1. Then, click the Save button to save the flow. For that, we need to enter the Flow Label; I have entered “Delete records for specific conditions.”
    • The API Name will automatically populate as we click the text box. The Description is optional; we can introduce our flow shortly.
Delete Record in Salesforce Flows
  1. After that, to check whether the flow is working, open the Opportunity record, try to update the “Close Lost” stage, and save the record.
    • Then, go to the Recycle Bin to see the deleted record.
How to Delete Records in Salesforce Flow
  1. As you navigate to the Recycle Bin, you will see which record you have updated to close the lost stage in the opportunity object.
    • That record is deleted and stored in the recycle bin.
Delete Records Using Salesforce Flows

This is how we can automatically delete the records using a flow in Salesforce.

Conclusion

I hope you now have an idea of how to delete conditional records that do not meet the business criteria. In that, we have seen how to delete records using a flow in Salesforce with a scenario and explanation.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.