Skip to main content

Code reviews rule: Untested flows

Written by David Martin
Updated this week

Untested flows

Why is this an issue?

Flows without automated tests may contain bugs that are only discovered in production. Flow testing:

  • Verifies flows work as expected

  • Catches regressions when flows are modified

  • Improves confidence in deployments

  • Documents expected behavior

Examples

Example of incorrect setup (flow without test):

force-app/
├── main/default/flows/
│ └── Create_Case_Flow.flow-meta.xml
└── (no corresponding test)

Example of correct setup (flow with test):

force-app/
├── main/default/flows/
│ └── Create_Case_Flow.flow-meta.xml
└── main/default/flowTests/
└── Create_Case_Flow_Test.flowTest-meta.xml

How can I fix violations?

Create flow tests using Salesforce's Flow Testing framework:

  1. Create a FlowTest: In Setup, navigate to Flow Tests and create a new test.

  2. Define test scenarios: Specify input values and expected outcomes.

  3. Run tests: Execute tests to verify flow behavior.

Alternatively, test flows via Apex:

@IsTest
static void testMyFlow() {
// Set up test data
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('recordId', testRecord.Id);

// Run the flow
Flow.Interview.My_Flow flow = new Flow.Interview.My_Flow(inputs);
flow.start();

// Verify results
Assert.areEqual(expected, flow.getVariableValue('outputVar'));
}

Resources

Did this answer your question?