Record deletion using Salesforce Flow

In this article, we will provide a detailed step-by-step guide on record deletion using Salesforce Flow.

Scenario

Delete the related opportunity records on Account object if the Stage of the Opportunity is equal to closed lost.

Creating the Flow

We will create a Screen Flow and place the Flow on the Account object records quick actions.

To begin the record deletion using Salesforce Flow, we’ll first obtain the Account record Id. This Id will help us identify and examine the related Opportunity records associated with the Account.

We will create a Flow resource of variable type to store the Account record Id.

In Salesforce Flow, a resource variable enables you to store and reference a resource, such as a custom formula or recordId in your Flow.

Resource for delete records using Salesforce Flow

The data type for this variable will be text. Since we are going to provide the Account record’s Id as input in our Screen Flow, we need to set Available for Input checkbox to True.

Want to Learn Salesforce Flows? Checkout our Salesforce Flow Course

Now we will fetch all the related opportunities in the Closed Lost stage using the Get record element.

Get Opportunity record for Record deletion using Salesforce Flow

As we are fetching all the related closed lost opportunities of an Account, under the How Many Records to Storeย criteria we will select All records.

Opportunity records to save for record deletion using Salesforce Flow

 

By utilizing the “Add Fault Path” feature on the Get Records element, you can set up an alternative path to capture and handle errors that may occur during the process of fetching opportunity records from the Salesforce org.

Fault path element

Now incorporate the Decision element into the Flow to verify the presence of opportunity records in our Get Records element.

If it contains some records, we will display the user whether we want to Delete the records or not.

Check for Opportunity record

If no opportunity records are found, a message will be displayed to the user indicating, “This Account record does not have any related opportunities in the closed lost stage.”

To display this message, we will add a screen element to the Null path of the decision element.

NoOpportunityRecord

We will also update the footer section of the screen element by hiding the Previous and Pause buttons.

Upon fetching an opportunity with the “closed lost” stage, users will be presented with the option to either delete the opportunity records or retain them.

To offer these choices to the user, we’ll incorporate the screen element and utilize the radio buttons component.

YesOrNo Selection

Optionally, you can set default values to be pre-selected for these radio buttons.

After providing the user with the option to choose whether to delete the opportunity or not, we will use the decision element to check their selected option.

Check Opp Delete or not

Delete Element in Salesforce Flow

To delete the opportunity record, we will use the Delete Records element. We have two options to find the records to delete.

  • Use the IDs stored in a record variable or record collection formula
  • Specify conditions

Having the Get record element storing all related opportunities of our Flow, we will proceed with the first option.

Confirm records to be deleted

If an error occurs while deleting the records, we can roll back the transaction using the fault path, preventing the deletion of the records.

Rollback Record Deletion

Add another screen element below the delete records element to show the user the message “All related opportunities with closed lost stage have been deleted.”

Final Deletion Message

Now our Flow is complete. Save the Flow and Activate it.

Add Flow to Account Object Quick Actions

Object Manager โžก Account Object โžก Button, Links and Actions

Create a new action by clicking on New Action button.

New Delete Action on Account Object

Navigate to the Account page layout and add this newly created quick action on the Account Layout.

Open any Account record and you will be able to see the quick action button been added to the page layout.

Quick Action Added on Account Record

Verify whether the Account record contains any opportunity with the stage equal to closed lost. If not, following message will display on the screen clicking the Delete Lost Opps button.

Output 1

If the Account record contains opportunity with the stage equal to closed lost and the user selects to delete the opportunity record then following message will display on screen.

Output 2

Business use case where we can perform record deletion using Salesforce Flow

  • Automate removal of completed or outdated events/tasks created by sales representatives, ensuring a clutter-free view of upcoming tasks.
  • Automate a check for duplicate accounts or contacts created during the lead conversion process, and remove them when converting a lead into an opportunity, which creates an account and a contact.
  • Remove the contact from specific email list if the contact unsubscribes from receiving any email communications from your company.
  • Automate removal of duplicate accounts from the Salesforce database based on specific criteria, like no recent activity.

For more details and complete solution to the business scenario checkout the video

Get complete Roadmap To Learn Salesforce Admin And Development ๐Ÿ‘‡

Spread the love

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *