function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chriscwharrischriscwharris 

Trigger error when record created from Flow

Hi, I have an custom object with a trigger that performs some validation not possible using validation rules. If the trigger criteria is met I use object.addError to throw an exception and that stops the INSERT/UPDATE running. This works fine when creating a record from a button in a view or from the parent object using the actual page layout etc..
Trigger Error Example
However I have created a Flow that is accessed via the Lightning Home page using the Flow Component. That all works fine except if the trigger throws the error, instead of getting a friendly message I get an api exception error with the correct message but it's not at all friendly. I also get a flow error email every time which isn't ideal since the error isn't actually the flow crashing it's just stopping the DML.

Flow Error Issue
Anyone offer a suggestion as to how to capture the api exception and stop it throwing the flow error? I want the message to display and the DML to be stopped but gracefully!
 
Gaurav HandooGaurav Handoo
Hi Chris

There is a variable viz. {!$Flow.FaultMessage} that captures the error message of the flow generated, you can use the same to capture the error message.

However, Record Create/Update of the flow, is a direct commit action and will always through an error. To avoid this, recommendation here is to extend your flow to add in critieria for your validation through a decision box and make sure data points not meeting the criteria never reach the Record/Update element.

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav