back to blog
Custom errors in Salesforce flows
October 04 2023 • 15 min read


We might have to throw errors to the user when a record is being created or updated or deleted based on the requirement.

Previously errors can only be thrown in apex and the developers had to work on it.

Salesforce’s Winter ‘24 release will be introducing  an exciting new element called “custom error” in flows. Admins can use this feature to add custom error messages in the flow process based on the user input. In this Blog we explain a case where a custom error can be thrown in the flow using this custom error element.

We will be throwing a custom error to the user whenever a second opportunity with the same name for an account is being created or updated.

ce 1



  1. From the Quick find search and select Flows → Click New Flow.


  1. Select Record Triggered flow  → Click Create.


  1. By default the layout is set to Auto Layout.


  1. Select Object as Opportunity
  2. Configure Trigger → A record is Created or Updated.
  3. In condition Requirements,  No conditions to be added.
  4. Optimize the flow for →  Select Fast Field Updates.


  1. Select (+) icon → Select Get Records Element.
  2. Select Object as Opportunity Object.
  3. Choose All Conditions Are Met (AND) as the condition requirement

               1. Opportunity Name Equals Record >Name

                       2. Account Id Equals Record>Account Id


  1. Select All Records option in How Many Records to Store.


  1. Since we are not performing any operation on any of the Opportunity fields, select the option Choose fields and let Salesforce do the rest so that we don’t have to pull all fields except Id.
  2. Click Done.
  3. Click the New Resource button on the left side of the canvas under the           
  4. Enter API Name as recordcount.
  5. Select Data Type as Number, decimal places as 2.
  6. Click Done.


  1. Below the  Get Records element add an Assignment element and enter the label as Count Opportunities.
  2.  Add the condition requirement as AND,

              recordcount as resource, Equals as operator and Count as value.

  1. Click Done.
  2. After the Assignment element add a Decision element.
  3. Enter the label as Check Count.
  4. Enter Outcome Detail label as Records found.
  5. In that Decision Element, add the following  condition 

       recordcount  >  0


  1. Add a Custom error element( this custom error element helps us to display an error when a user enters the same name for a second opportunity for an account.


  1. Choose the type of error you want, enter the error message that you want to display.
  2. Click Save & Activate.


In this blog we have covered how to display custom error messages to the user using a custom error element in a record triggered flow.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech