Sub topic 16
Testing and debugging before cutover
This chapter assumes you have built or generated a record-triggered flow and have a sandbox or Developer Edition org. You should know basic Apex syntax and be able to read a debug log. Testing happens before you deactivate the old automation, so the old and new versions never both run in production.
What to test
A migrated flow can fail in three ways: it does not fire, it fires when it should not, or it breaks at volume. Cover each one.
- Entry conditions. Create or edit one record that should qualify and one that should not. Confirm that only the first triggers the flow.
- Changed-value logic. If the old rule used ISCHANGED or "only when a record is created or edited to meet criteria," edit the record twice without changing the key field. The flow should run once.
- Actions. Check every field update, email, task, and related record the old automation produced. Compare the results with what the old automation produced.
- Bulk behavior. Update 200 records in one transaction.
Debug a single record
In Flow Builder, open the flow and use Debug. For a record-triggered flow, choose the triggering record and whether it is an insert or update. Enable Run flow in rollback mode to see the results without saving changes to the database. Rollback mode is the safer choice while the old automation is still active.
The debug output lists each element that ran, the values it read, and the values it wrote. If a decision outcome is wrong, look at the formula inputs first. A common cause is a picklist compared without TEXT().
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}Test in bulk with Apex
Flow Builder debugging handles one record. An Apex test exercises the real transaction path with 200 records, which is the batch size Salesforce uses when it splits a large data load.
@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 assumes the flow creates one Task per Opportunity that becomes Closed Won. Adapt the stage and the assertion to your flow. Test.startTest() and Test.stopTest() give the update its own set of governor limits, so a limit failure points at the flow and not at test setup.
Debug failures
- Flow did not run. Check that the flow is active and that the entry conditions and run frequency match the old criteria.
- Fault email or error on save. Open the flow's fault path or the error message, and find the element named in it. Common causes are required fields, validation rules, and missing permissions.
- Duplicate results. Check whether the old Workflow Rule or process is still active. Also check for other flows on the same object.
- Limit errors in bulk. Look for Get Records, Create Records, or Update Records elements inside a loop. Move them outside the loop.
For failures you cannot explain, turn on a debug log for the running user and read the flow interview entries in the log.
Exercise
A migrated flow passes every single-record debug run but fails in an Apex test that updates 200 records. What is the most likely cause, and where do you look?
Show answer
A data element, such as Get Records or Update Records, probably sits inside a loop, so the flow hits a governor limit at volume. Open the flow and move the data element outside the loop, then rerun the test.