0

I would like to prevent a certain branch of a flow to be executed in certain condition and have the flow fail and return an error to the user. I haven't, however, found out how to throw an error from the flow if a query returns, for example, 0 results.

Is there a suggested way to throw errors from flows?

3 Answers 3

1

In situations like these where you want to throw an error from flow:

  1. Create a checkbox field and hide from page layout.
  2. At the end of the branch of the flow where you want to trigger that error message just update the checkbox to true or if it is true set to false.
  3. Create a validation rule with the desired error message and include that if ISCHANGED(field) then it should be invoked.
0

AFAIK, there isn't an "out of the box" flow element to throw errors. On the DML flow elements (such as create record, update record etc.), you can use a fault connector to handle error scenarios. You will have make use of decision element (for situations like zero records returned) and take an appropriate action (such as setting an output value, calling a invocable apex, skip a branch execution, display an error message to user etc.).

5
  • How do you display errors in case of non screen flow ?
    – Edmondo
    Jan 10, 2021 at 17:58
  • Can you elaborate on how and where you are trying to display error? basically explain a bit on the use case.
    – arut
    Jan 11, 2021 at 3:12
  • So the use case is an autolaunched flow that can also be invoked via a custom button using url for. I want the flow to fail if a collection of objects associated to the current object is empty
    – Edmondo
    Jan 11, 2021 at 7:22
  • A custom button isn't something to which you can return a response. Have you considered breaking up the existing flow in auto-launched sub flow and screen flow? You could use them instead of button and you can have resources in them marked as available for input and output; that way you can track if no records are fetched and display relevant message to user.
    – arut
    Jan 11, 2021 at 17:21
  • An idea available to have the exception element in flow. ideas.salesforce.com/s/idea/a0B8W00000K4OY4UAN/…
    – sf dev
    Sep 2, 2022 at 13:23
0

Until Winter 24 release this could be done with a Before Save Flow and a Validation rule. Now with the Winter 24 release we can use Custom Error component in Flow to display a custom error message. You can use the Custom Error feature to undo a change that started a process and inform the user about the specific problem. This allows the user to correct the issue and try again. For example, if a user tries to delete a record that starts a process, the process can provide an error message explaining why the deletion was not allowed. You can also combine your custom error message with built-in {!$Flow.FaultMessage} error message to produce a more detailed error message.

Considerations

  1. A Custom Error element can contain only one record page error message. To create another record page error message in the same flow, use another Custom error element.
  2. A field can have only one error message, but each field can have an error message.
  3. Compound fields aren’t supported.
  4. If an executed fault path has a Custom Error element, the change that triggered the flow is rolled back.
  5. Custom error messages use the same functionality as the addError() Id method in Apex.

Source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .