Sub topic 8
Returning useful results when something fails
This chapter assumes you can build an autolaunched flow, define input and output variables, and use Get Records and Decision elements. It covers how to make a flow return a result the agent can use when a lookup finds nothing or an operation fails.
Why failures need a plan
An agent calls your flow and then reads the output variables. It cannot read a flow error screen or an email sent to an admin. If the flow ends with an unhandled fault, the agent gets a generic failure and has nothing useful to say to the customer. It may retry, guess, or give a vague answer.
Plan for two kinds of problems:
- Expected empty results. A Get Records element finds no record because the customer typed the wrong case number. This is not a system error. The flow continues normally.
- Faults. A DML element (Create, Update, Delete) or a Get Records element fails, for example because of a validation rule, a record lock, or a missing permission. The flow follows a fault path if you connect one.
In both cases, the goal is the same: finish the flow normally and set an output the agent can read aloud.
Add an output that carries the message
The caseStatus output from the earlier example has a description that allows for a message when no case is found. Use that pattern. Either reuse one output for both results, or add a separate errorMessage output when the agent needs to tell success from failure.
<variables>
<name>errorMessage</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>Empty when the lookup worked. Otherwise a short, plain-language reason it failed, such as "No case was found with that number."</description>
</variables>The description matters here too. The agent reads it to decide whether to treat the output as a problem.
Handle an empty result
Add a Decision element after Get Records. Check whether the record variable is null, or whether the Get Records element found anything.
- Get Records looks up the Case by
caseNumber. - A Decision named "Case Found?" checks that the stored record is not null.
- On the found path, an Assignment sets
caseStatusto the record's Status. - On the not-found path, an Assignment sets
errorMessageto "No case was found with that number."
Both paths end the flow normally. The agent receives a clean answer either way.
Handle a fault
Select an element that can fail and add a fault path. In Flow Builder, a fault connector appears when you choose the element's fault option. Connect it to an Assignment that sets errorMessage.
Write the message for the customer, not for a developer. "I couldn't update the case right now. Please try again later" is usable. A raw system message such as a validation rule error or a row-lock exception is not.
You can read the technical detail from the $Flow.FaultMessage global variable. Store it in a text variable and write it to a Flow log, a custom log object, or a Platform Event for your team. Do not put it in an output the agent reads.
Fault path:
1. Assignment: errorMessage = "I couldn't update that case right now. Please try again later."
2. Create Records: Flow_Error_Log__c with Message__c = {!$Flow.FaultMessage}
3. End the flow normallyFlow_Error_Log__c is an example custom object. Create your own or use another logging approach.
How the paths fit together
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| No null check after Get Records | The flow reads a field from an empty record and faults | Add a Decision before using the record |
| Exposing `$Flow.FaultMessage` in an output | The agent may repeat internal details to the customer | Log it and return a plain message |
| Same text for every failure | The agent cannot suggest a next step | Use distinct, specific messages |
| Message not described in the output description | The agent may ignore the output | Say in the description when it is filled |
Exercise
A Get Records element finds no Case for the number the customer gave. Should this go down the fault path? What should the flow return?
Show answer
No. An empty result is not a fault, so the flow continues normally. A Decision checks whether a record was found. On the not-found path, an Assignment sets an output such as errorMessage to "No case was found with that number." The flow then ends normally so the agent can tell the customer.
Exercise
Why should you write $Flow.FaultMessage to a log instead of returning it in an output variable?
Show answer
The message holds technical detail that the agent may repeat to the customer and that the customer cannot act on. Logging it keeps the detail available to your team, while the output returns a short, plain-language message.