Step by Step Guide to "Custom Error" in Record-Triggered Flow

A New Feature Introduced in Salesforce Winter ’24 Release

Salesforce's Winter ’24 release introduced an exciting new element called “Custom Error” in Record-Triggered Flow. This feature enables you to display custom error messages on the UI, either as a pop-up window or as an inline error on a field. When the message is displayed, the associated record change is rolled back.

Why is this feature valuable?

This feature is particularly useful as it allows you to perform complex validations in Flows, assess the outcomes using the “Decision” element, and then display a “Custom Error” message if the validation fails. Salesforce will automatically roll back changes to the record after displaying the error message. Previously, you would have needed to write an Apex trigger to perform such complex validations.

Example and Business Use Case

In Salesforce, if you have a master-detail relationship between two objects and you delete the master record, Salesforce automatically deletes the child records as well. If you want to prevent the deletion of the master record when child records exist, this previously required writing a trigger.

With the Winter ’24 release, you can now meet this requirement using the “Custom Error” element. In this guide, we'll create a Record-Triggered Flow to stop the deletion of a master record when child records exist in a master-detail relationship.

Other Use Cases

Some other scenarios where you can utilize this feature include:

  • Creating dynamic discount validations that consider factors like customer segment, product category, and regional pricing strategies.

  • Preventing accounts from the same region or industry from being owned by competing sales reps.

  • Validating values in fields across multiple related objects.

Observations

Here are some of my observations on the Custom Error element in the flow:

  • This element is available only in Record-Triggered Flow. It is not available in other types of Flows.

  • If you add other elements (e.g., “Assignment” or DML elements) after the “Custom Error”, the flow continues execution and commits the transaction. The error message is not shown, and the record is not rolled back.

Invest 15–20 minutes in following this guide, and you might be able to replace some of your Apex triggers. Not a bad return on investment, if you ask me.

References & Useful URLs