Sub topic 16
Testing and debugging before cutover
This chapter assumes you have built or generated a record-triggered flow from a Workflow Rule or Process Builder process, and that you can work in a sandbox or Developer Edition org. You should know basic formula syntax and how entry conditions work. The goal is to prove that each migrated flow does what the old automation did, in bulk, and without firing twice.
What you are proving
A migrated flow can fail in ways the old automation did not. A test plan should cover four questions:
- Does the flow fire when the old automation fired, and stay silent when it did not?
- Does it produce the same outcome: the same field values, tasks, emails, and related records?
- Does it behave correctly when 200 records arrive in one transaction?
- Does it avoid double execution while the old automation and the new flow both exist?
Write these as a test matrix before you open Flow Builder's debugger. One row per old criteria branch, one row per action, plus rows for "should not fire" cases.
| Case | Input | Expected result |
|---|---|---|
| Positive | Opportunity moves to Closed Won with Amount 150,000 | One follow-up Task created |
| Negative | Opportunity moves to Closed Won with Amount 50,000 | No Task |
| Not changed | Closed Won opportunity edited, stage unchanged | No new Task |
| Bulk | 200 opportunities set to Closed Won at once | 200 Tasks, no limit errors |
| Overlap | Old automation and new flow both active | Exactly one Task, not two |
Test in layers
Use three layers, from fastest to most realistic.
- Flow Builder Debug. Quick feedback while you build.
- Manual end-to-end tests in a sandbox. Real saves from the UI, API, or data load.
- Apex tests. Repeatable bulk tests that run again at deployment.
Debugging in Flow Builder
Open the flow and choose Debug. For a record-triggered flow, you pick the triggering action (create, update, or delete) and supply or select a record. Two options matter:
- Run flow in rollback mode. The debug run executes real DML, but Salesforce rolls the changes back, so you can repeat tests without leaving data behind. Rollback mode does not undo everything. Emails, callouts, and other external actions can still occur, so check what your flow does before you debug against real contact records.
- Select the record to debug. For update flows, choose an existing record and set the new values so that
$Recordand$Record__Priordiffer in the way your entry condition expects.
The debug output lists each element the flow ran, the values of variables at each step, and which decision outcome it took. If the flow never reached your decision, look at the entry conditions first. If it reached the decision and took the wrong branch, compare the formula values shown in the output.
Common formula mistakes found in debugging
Most migration bugs come from translating formulas by hand. The Workflow Rule and flow syntax differ for picklists and for change detection.
Workflow Rule formula:
AND(ISPICKVAL(StageName, "Closed Won"), Amount > 100000)
Flow entry condition (Formula Evaluates to True):
AND(TEXT({!$Record.StageName}) = "Closed Won", {!$Record.Amount} > 100000)
Workflow ISCHANGED(StageName) in a flow:
{!$Record.StageName} <> {!$Record__Prior.StageName}If the Workflow Rule used ISPICKVAL and you copied it into a flow formula, the formula fails to save or evaluates incorrectly. Use TEXT() instead. If the old rule used ISCHANGED or PRIORVALUE, the flow needs an update-triggered flow that compares $Record against $Record__Prior.
Also check these:
- Null values. A blank
Amountin a comparison can behave differently than you expect. Test with blank fields. - Run frequency. A Process Builder criteria node set to "only when the record is changed to meet the criteria" maps to the flow option to run only when the record is updated to meet the condition requirements. If you chose "every time a record is updated and meets the condition requirements," the flow fires on every save, so a Closed Won record edited later creates another Task.
- Cross-object formulas.
$Record.Account.Industrycan be null if the lookup is empty. Test records with no parent.
Reading the evidence of a real run
Debug runs are useful but they are not the same as a real save. After a manual test in the sandbox, check the following.
- Flow interview details. In Setup, use Paused and Failed Flow Interviews to see interviews that failed. For fault emails, Salesforce sends an unhandled-fault message to the user who last modified the flow, or the one you configured in Process Automation Settings.
- Debug logs. Create a trace flag for the test user, then set the Workflow category to
FINERor higher. Log lines such asFLOW_START_INTERVIEW_BEGIN,FLOW_ELEMENT_BEGIN, andFLOW_BULK_ELEMENT_BEGINshow which flow ran and which elements fired. Count theFLOW_START_INTERVIEW_BEGINlines for one save. If you see two interviews for the same flow where you expected one, a duplicate trigger exists. - Record history and related lists. Verify the actual field values, Task counts, and email logs, not only that the flow ran.
Checking for double firing
During migration, the old Workflow Rule or process and the new flow often coexist in the sandbox. Test each in isolation, then together.
- Deactivate the old automation. Run the test. The flow alone should produce the expected result.
- Reactivate the old automation and deactivate the flow. Run the same test. Record the old result as your baseline.
- Activate both. If the output doubles, you have confirmed the overlap that cutover must remove.
Workflow field updates can also cause the record to be evaluated again, which can re-fire other automation. Compare the baseline counts against the migrated counts for every object touched. Flows that update the same record they were triggered from should use a before-save flow when possible, since it avoids an extra save and extra trigger evaluation.
Bulk testing with Apex
Flows run through the same bulk path as Apex. A flow that works for one record can still fail when 200 records save together, usually because an element such as Get Records, Create Records, or an action sits inside a loop. The Apex test below checks the Closed Won scenario with 200 records. Adapt the stage value and assertion to your own flow.
@IsTest
private class ClosedWonFlowTest {
@IsTest
static void bulkClosedWonCreatesOneTaskEach() {
List<Opportunity> opps = new List<Opportunity>();
for (Integer i = 0; i < 200; i++) {
opps.add(new Opportunity(
Name = 'Test ' + i,
StageName = 'Prospecting',
CloseDate = Date.today().addDays(30)
));
}
insert opps;
for (Opportunity o : opps) {
o.StageName = 'Closed Won';
}
Test.startTest();
update opps;
Test.stopTest();
System.assertEquals(200, [SELECT COUNT() FROM Task WHERE WhatId IN :opps]);
}
}The test inserts records at Prospecting, so the flow should not fire on insert. The update then changes all 200 to Closed Won. Test.startTest() and Test.stopTest() give the update its own set of governor limits and run any asynchronous work, such as scheduled paths with no wait, before the assertion. The assertion counts one Task per opportunity, which catches both missing and duplicate tasks.
Add more tests in the same class for the negative cases: an Amount below the threshold, an unchanged stage, and a record with blank fields. Mixed batches are valuable too. Update 100 records that meet the criteria and 100 that do not, and assert the exact count of results.
Governor limit symptoms
When a flow breaks in bulk, the error names the limit.
| Error text | Likely cause in the flow |
|---|---|
| Too many SOQL queries: 101 | Get Records element inside a loop |
| Too many DML statements: 151 | Create, Update, or Delete Records inside a loop |
| Too many DML rows: 10001 | Flow or Apex updating more records than a transaction allows |
| CPU time limit exceeded | Heavy loops, many flows on the object, or a recursive update |
Fix these by moving data operations out of loops. Collect records into a collection variable inside the loop, then run one Create, Update, or Delete Records element after the loop ends.
Testing scheduled paths
Scheduled paths replace time-dependent actions, and they are the hardest part to test because they run later. Several approaches help:
- Use a short offset in the sandbox, such as 5 minutes, then restore the real offset before deployment. Record the real value in your test notes so you do not forget it.
- Check Scheduled Jobs (or the Flow Interviews view of pending jobs) in Setup to confirm that the path queued for each record.
- Change the record so it no longer meets the entry condition, and confirm the pending action is cancelled where the old Workflow Rule would also have cancelled it. This behavior depends on the entry condition and run frequency, so verify it directly instead of assuming it.
Debugging checklist when a flow misbehaves
- Is the flow active, and is the active version the one you edited?
- Did the trigger fire (create, update, or both)? Check the object and the "when to run" setting.
- Does the entry condition evaluate as expected for the test record? Test the formula in the debugger with the exact values.
- Did a Decision send the record down the intended path, and is the default outcome handled?
- Did a Get Records element return nothing? Decide what the flow should do with a null result.
- Did a user without access run the save? Flows triggered by a record change run in system context by default, but check this setting if the old process behaved differently.
- Did another flow, trigger, or validation rule change the record or reject it? The order of execution and other automation on the object matter here.
Fault paths
Process Builder failures usually surfaced as an error to the user or as an email. In a flow, add a fault connector to each element that can fail, and route it to a consistent handler. The handler can write a log record to a custom object, send an email, or stop the flow with a message. Test the fault path by forcing a failure, for example by creating a record that violates a validation rule.
Exercise
A migrated flow creates a follow-up Task when an Opportunity becomes Closed Won. In the sandbox, a user edits a Closed Won opportunity's description, and a second Task appears. The old Process Builder process only fired when the stage changed to Closed Won. What is the most likely cause, and how do you confirm and fix it?
Show answer
The flow's run frequency or entry condition is too broad. It probably runs every time a record is updated and meets the condition, or the entry condition checks only that the stage is Closed Won and does not compare against the prior value. Confirm by debugging an update that changes only the description and by counting FLOWSTARTINTERVIEWBEGIN lines in the debug log. Fix it by setting the flow to run only when a record is updated to meet the condition requirements, or by adding {!$Record.StageName} <> {!$Record_Prior.StageName} to the entry condition. Then rerun the negative test case to prove no second Task is created.
Exercise
Your Apex test passes with 1 record but fails with 200 records and reports "Too many SOQL queries: 101". Name the likely flow design mistake and the fix.
Show answer
A Get Records element is placed inside a loop, so it runs one query per record. Move the Get Records element before the loop, retrieve all needed records into a collection, and read from that collection inside the loop. Do the same for any Create, Update, or Delete Records elements by collecting records in the loop and running one DML element after it.