Trigger a Flow to Run Before a Record Is Deleted

In Flow Builder, you can now configure a new record-triggered flow to run before a record is deleted. You no longer need to write Apex code to set this up. This autolaunched flow runs in the background and updates related records when a record is deleted.

Where: This change applies to Lightning Experience and Salesforce Classic in Essentials, Professional, Enterprise, Performance, Unlimited, and Developer editions.

Who: To activate a record-triggered flow that runs before the record is deleted, you need the Manage Flows and View All Data permissions.

Why: For example, suppose that your Salesforce org has a custom field on the Account object that tracks the total items related to that account. Without automation, this field is updated manually every time a related item is deleted. Now, you can automate this task with a record-triggered flow that runs before a record is deleted.

The flow runs anytime an item is deleted. It finds the related account, and decrements the total number of items. When the flow finishes, the item that launched the flow is deleted.

Flow canvas that shows the Start, Get Records, and Update Records elements

How: When creating a flow, select Record-Triggered Flow.

The New Flow window with the Record-Triggered Flow selected

To configure the flow to run before a record is deleted, click Edit on the Start element.

Flow canvas that shows the Start element

Select A record is deleted and you’re ready to build the flow.

The Start element window that shows the A recod is deleted option

The flow can access any record and perform actions before the record that launched the flow is deleted from the database. The $Record global variable contains the Salesforce record that launches the flow.

Considerations for record-triggered flows:
  • Launching a flow after restoring a record via the undelete operation is not supported.
  • Displaying custom error messages via the addError() method is not supported in invocable actions.