Sub topic 7
Building the flow logic: Get Records, decisions, and updates
This chapter assumes you know Flow Builder basics (variables, elements, resources) and the Salesforce data model. It also assumes you have already defined the input and output variables for your action. Here you build the logic between them: look up a record, branch on the result, and set the output variables the agent will read.
The shape of an action flow
An action flow runs without a screen and without a human. The agent passes in the inputs, the flow runs, and the agent reads the outputs. Keep the path short and make every path end by setting each output variable.
Get Records
Get Records reads data. For an action that returns one answer, configure it like this:
- Choose the object and filter on the input variable, for example
CaseNumberequals{!caseNumber}. - Store only the first record, so you work with a single record variable instead of a collection.
- Select only the fields you need. This keeps the query small and avoids exposing extra data.
In the flow metadata, the element looks like this:
<recordLookups>
<name>Get_Case</name>
<label>Get Case</label>
<connector>
<targetReference>Case_Found</targetReference>
</connector>
<faultConnector>
<targetReference>Lookup_Failed</targetReference>
</faultConnector>
<filterLogic>and</filterLogic>
<filters>
<field>CaseNumber</field>
<operator>EqualTo</operator>
<value>
<elementReference>caseNumber</elementReference>
</value>
</filters>
<getFirstRecordOnly>true</getFirstRecordOnly>
<object>Case</object>
<queriedFields>Id</queriedFields>
<queriedFields>Status</queriedFields>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordLookups>The faultConnector is the fault path. The next chapter covers it in detail.
Decisions
A Get Records element that finds nothing does not fail. It leaves the record variable empty and the flow continues. Add a Decision element straight after it and check whether the record variable (or its Id) is null. Without this check, the flow may set an output from an empty record, and the agent may report a blank answer as fact.
Decisions also handle the inputs themselves. The agent supplies the values, so they can be missing or in a different format than you expect. Case numbers are stored with leading zeros, such as 00001026. A user may say "1026", and the agent may pass that on unchanged. Either normalize the input in the flow or say in the input description what format is required.
Updates
If the action changes data, use Update Records or Create Records, and be strict about scope:
- Update only the fields the action's purpose requires.
- Update by
Idfrom a record you just retrieved. Do not use broad filter conditions that could match many records. - Set an output that confirms what happened, for example "Case 00001026 was escalated." The agent can only report back what the flow returns.
Outputs on every path
| Path | What the flow should return |
|---|---|
| Record found | The real value, such as the case status |
| No record found | A short message saying nothing matched |
| Fault | A short message saying the lookup failed |
Every path should set the output variable. If one path leaves it blank, the agent has nothing useful to say.
Exercise
In the Get Case Status flow, the Get Records element finds no case for the number the user gave. Why must you add a Decision after it, and what should the "not found" path do?
Show answer
Get Records does not fail when it finds nothing. It leaves the record variable empty and the flow carries on. A Decision that checks for an empty record lets the flow take a separate path. That path should set the output variable (caseStatus) to a short message such as "No case was found with that number", so the agent has a usable result and does not report a blank or made-up status.