Sub topic 11
Diagnosing common flow failures
This chapter assumes you can build a record-triggered flow, run Flow Builder debug, and read a debug log at a basic level. You should also know what a fault path is and what the governor limits are. Earlier chapters covered those tools. Here you use them to diagnose the failures that come up most often in real orgs.
Start with the symptom
Flow failures show up in one of four ways, and each points to a different place to look.
- The user sees an error message on screen, and the save is rolled back.
- An email from Salesforce reports that a flow interview failed.
- The flow runs without an error but does the wrong thing.
- The flow does not seem to run at all.
The first two have an error message, which you can usually match to a known cause. The last two have no error, so you have to find where the flow's behavior differs from what you expected.
Failures that produce an error
Governor limit errors
Governor limits cap how much work one transaction can do. A flow shares its transaction with other automation on the same save, such as Apex triggers, other flows, and workflow field updates. A flow can fail on a limit even when it looks small.
| Error text | Limit | Typical flow cause |
|---|---|---|
| Too many SOQL queries: 101 | 100 queries per synchronous transaction | A Get Records element inside a loop |
| Too many DML statements: 151 | 150 DML statements | Create, Update, or Delete Records inside a loop |
| Too many DML rows: 10001 | 10,000 rows per transaction | A large collection written in one step, or several flows each writing many rows |
| Apex CPU time limit exceeded | 10,000 ms synchronous | Many flows and triggers on one object, or large loops with many assignments |
| Number of iterations exceeds the limit | 2,000 executed elements per interview | A loop over a large collection, or a loop that never ends |
The fix for the first two is the same pattern each time. Move the query or DML out of the loop. Inside the loop, only assign values and add records to a collection variable. After the loop, run one Get Records or one Update Records on the whole collection.
For CPU time, open the debug log and look at the CUMULATIVE_LIMIT_USAGE section. It shows which automation used the time. If three flows and a trigger all run on the same object, consolidating them into fewer flows often helps more than tuning any single one.
A single-record test hides these problems. A flow that queries inside a loop passes with one record and fails at 101. This is why the bulk tests from the previous chapter matter.
Unhandled fault: required fields, validation rules, and access
Many errors come from the database, not from the flow logic. The flow tries a Create or Update Records element, and the save is rejected. The message names the cause:
REQUIRED_FIELD_MISSINGmeans the flow did not set a field that the object requires. Check the Create Records element. Also check whether a Get Records result was empty, so the value you mapped was blank.FIELD_CUSTOM_VALIDATION_EXCEPTIONmeans a validation rule blocked the save. The message contains the rule's error text. The flow is working, but its data fails the rule. Either set the field correctly or adjust the rule to allow the automated change.INSUFFICIENT_ACCESS_OR_READONLYorINSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITYmeans the running user lacks access. Check how the flow runs. Record-triggered flows run in system context by default. Screen flows started from a button, and flows run from other places, can run in user context and obey field-level security and sharing.UNABLE_TO_LOCK_ROWmeans another transaction holds a lock on the record. It tends to appear when many users or integrations update the same parent record at once. For example, many child records updating one Account. Reduce updates to the shared parent, or move the work to an asynchronous path.
Add a fault path to every element that writes data. Without one, the user sees a generic error and the whole transaction rolls back. With one, you can write the message to a log record or send it to an administrator:
An error occurred in the flow: {!$Flow.FaultMessage}
Flow: {!$Flow.CurrentDateTime}
Record Id: {!$Record.Id}$Record.Id works only in record-triggered flows. In other flow types, pass the record ID in through a variable.
A fault path changes the outcome. If the fault path ends normally, the flow treats the error as handled and the transaction can still commit. Be deliberate about this. If a failed step should stop the whole save, the fault path should end by showing an error to the user or by throwing the failure forward, not by quietly continuing.
Null values and unset variables
The message "The flow failed to access the value for X because it hasn't been set or assigned" has one cause. A variable or record field that the flow used was empty.
The usual source is a Get Records element that found nothing. By default, Flow stores nothing in the record variable and carries on. A later element that reads {!Get_Account.Industry} then fails.
Fix it by adding a Decision element after each Get Records. Test whether the record variable is null ({!Get_Account} Is Null equals False) before you use it. For Get Records on multiple records, check the collection the same way before you loop.
Infinite loops and recursion
A record-triggered flow that updates its own triggering record in an after-save flow causes a second save. That save can fire the same flow again. If the entry conditions are always met, you get a recursion. It ends with an error such as "maximum trigger depth exceeded" or a limit error.
Three practices prevent it:
- Use a before-save flow when you only change fields on the triggering record. It does not cause a second save, and it is faster.
- Set the entry condition to Only when a record is updated to meet the condition requirements. The flow then runs only when the record changes from not matching to matching.
- Make the flow's update change the condition it tests, so the second pass fails the entry criteria.
A loop element inside one interview has a different failure. A loop over a collection ends by itself. A loop built from a Decision that points back to an earlier element does not. If the same element repeats in the debug run, you are in that case. The 2,000-element limit stops it, but the error is misleading. The real fault is the missing exit condition.
Callouts and asynchronous work
A flow that calls an external system in a record-triggered, after-save context cannot do so in the same synchronous transaction. Put the callout on the Run Asynchronously path of the record-triggered flow. The error you see when you skip this tells you callouts are not allowed there. It is a design error, not a data error, and the fix is to restructure the flow.
Failures with no error
The flow did not run
If nothing happens, work down this list. Each item is a quick check.
- Active version. Open the flow in Setup and confirm one version is active. Saving a new version does not activate it. A new version that is still a draft does not run.
- Trigger and event. Confirm the flow is set to run on create, update, or both. A flow set to "A record is created" ignores edits.
- Entry conditions. Compare the record's field values with the conditions. A picklist API value can differ from its label, and a formula may evaluate in a way you did not expect.
- Order of execution. A before-save flow runs before validation rules and after-save automation. If a field was changed by another flow or trigger earlier or later, the value the flow sees may not be the one you assumed.
- Scheduled or asynchronous timing. Scheduled paths and scheduled flows run later. Check the schedule and the running user before you conclude they did not run.
Use debug to confirm. If Flow Builder debug runs the logic fine against the same record, the logic is correct and the problem is activation or entry conditions.
The flow ran but gave the wrong result
Wrong results come from three common sources:
- Stale values. In an after-save flow,
$Recordholds the saved values, and$Record__Priorholds the values before the change. Mixing the two up gives results that are off by one edit. - Formula and data type mismatches. A text value compared to a number, or a date compared to a date-time, may evaluate differently than you expect. Check each Decision condition's inputs in the debug view.
- Multiple flows on one object. Two flows that both change the same field give a result that depends on run order. Flow ordering for record-triggered flows can be set in Flow Trigger Explorer in Setup. Prefer one flow per object and trigger event when that fits your team.
Debug shows each element's inputs and outputs. Step through to the first element where the actual value differs from your expected value. Everything before it is fine, so the fault is in that element or in the one that fed it.
Reading a failure in a debug log
When a flow fails in real use, you can't rerun it in the debugger with the same context. Set a trace flag on the user, reproduce the action, and open the log. Search for FLOW_ELEMENT_ERROR, which marks the failing element. This is a shortened, illustrative excerpt:
FLOW_START_INTERVIEWS_BEGIN|1
FLOW_ELEMENT_BEGIN|Update_Opportunity_Tasks|FlowRecordUpdate
FLOW_ELEMENT_ERROR|The flow failed to access the value for Get_Owner.Email because it hasn't been set or assigned.|FlowDecision|Check_Owner
FATAL_ERROR|System.FlowException: ...The element name in the error tells you where to look in Flow Builder. The text tells you the category, such as a limit, a null value, or a database rejection. Read the lines just before it to see which records and which interview were running.
A repeatable diagnosis routine
- Write down the exact symptom and the record involved.
- If there is an error, note the element name and the error code or message.
- Classify it: limit, database rejection, null value, recursion, or design error.
- Reproduce it in debug or with a trace-flagged action using the same record or the same volume.
- Fix the cause. For limit errors, move queries and DML out of loops. For null values, add a Decision. For database rejections, fix the data or the rule.
- Add a test that would have caught it. Use a flow test for a single-record logic error and a 200-record Apex test for a limit error.
- Add or update a fault path so the next failure produces a useful message.
Exercise
A record-triggered flow on Opportunity passes in debug with one record. After a data load of 500 Opportunities, the load fails with "Too many SOQL queries: 101". What is the most likely cause, and what is the fix?
Show answer
A Get Records element is most likely inside a loop, so each record in the batch runs a query. The data load batches records into one transaction, and the 101st query hits the limit. Move the Get Records before the loop, or after collecting the IDs, and query once for all records. Use assignments inside the loop to build a collection. Confirm the fix with a 200-record Apex test.
Exercise
A flow's Get Records finds no matching Account. The next element reads {!Get_Account.Industry} and the flow fails with "The flow failed to access the value for Get_Account.Industry because it hasn't been set or assigned." How do you prevent this?
Show answer
Add a Decision element straight after Get Records that checks whether {!Get_Account} is null. Send the null outcome to a branch that handles the missing record, for example by ending the flow or writing a log. Send the not-null outcome to the element that reads the field.
Exercise
A record-triggered after-save flow updates the same Opportunity it was triggered by and then fails with a trigger depth or limit error. Give two ways to stop the recursion.
Show answer
Change to a before-save flow if the update only sets fields on the triggering record. Or set the entry condition to run only when the record is updated to meet the conditions, so the second save does not match the criteria again. Making the update change a field that the entry criteria test also works.