What Is the Flow Unit Test Feature?
The Flow Unit Test feature in Salesforce allows you to automatically test flows without writing any code.
With this feature, you can:
- Simulate record creation or updates
- Run the flow automatically
- Verify that the flow followed the correct logic
- Check if fields were updated or actions were performed
Flow Unit Tests work in a similar way to Apex tests, but they are completely no-code.
Why Did Salesforce Introduce Flow Unit Tests?
Before this feature, testing flows meant:
- Manually creating records
- Changing field values
- Checking results by hand
This approach was slow and unreliable.
The Flow Unit Test feature was introduced to:
- Improve flow quality
- Reduce human errors
- Support test-driven development
- Make deployments safer
Key Capabilities of the Flow Unit Test Feature
- Test record-triggered flows
- Test auto-launched flows
- Simulate created or updated records
- Define assertions to validate results
- Add custom failure messages
- View detailed test run paths
What Flow Unit Tests Do NOT Do
It’s also important to know the limitations:
- Screen Flows cannot be tested
- User interactions are not supported
- Some external actions may require mocking
Even with these limits, the feature is extremely powerful.
Think in Terms of the Flow Plan
When creating flow tests, avoid thinking about flow elements like Decision or Update Records.
Instead, focus on the flow plan by asking:
1. When Will the Flow Run?
- On record creation?
- On record update?
2. What Will the Flow Do?
- What conditions should it check?
- What actions should it perform?
This approach keeps tests business-focused and easy to understand.
Flow Scenario: Check Escalated in Cases
Let’s now apply Flow Unit Testing to a real scenario.
When Will the Flow Run?
- When a Case is created
- When a Case is updated
What Will the Flow Do?
For all users, the flow should:
If Status = Escalated and Escalated = False
→ Set Escalated = True
→ Send a notification email to the Account Owner
Important Assumptions Before Testing
- The flow already contains the necessary elements
- Do not modify elements before writing tests
- Existing data is already clean
- Good data hygiene simplifies automation logic
Test-Driven Development Using Flow Unit Tests
Flow Unit Testing follows the Test-Driven Development (TDD) approach:
- Write the test first
- Run the test (it may fail)
- Fix the flow
- Run tests again
- Clean up descriptions and labels
Test 1: Case Created with Escalated Status
Goal
Verify that when a Case is created with:
- Status = Escalated
- Escalated = False
The flow sets Escalated = True.
Assertions
- The correct decision path was taken
- Escalated field was updated to True
Custom failure messages help quickly identify issues.
Test 2: Case Updated to Escalated
Goal
Verify that when a Case is updated from:
- Status = Working → Escalated
The flow again sets Escalated = True.
Running the Tests
When the tests are run for the first time:
- The decision logic passes
- The field update fails
This shows the real value of Flow Unit Tests.
Fixing the Flow and Re-Running Tests
After correcting the update logic:
- Run all tests again
- All tests pass successfully
This confirms the flow now behaves exactly as planned.
Clean-Up Step (Often Ignored but Important)
After fixing functionality:
- Update element descriptions
- Ensure labels match behavior
Clean flows are easier to maintain and troubleshoot.
Why the Flow Unit Test Feature Is a Game-Changer
Flow Unit Testing:
- Finds issues early
- Reduces production bugs
- Builds trust in automation
- Encourages better design
- Requires no Apex code
It turns Flow development into a professional, test-driven process.
Final Thoughts
The Flow Unit Test feature is one of the most important improvements in Salesforce’s low-code platform.
If you build flows, testing them should be a habit, not an option.
Well-tested flows mean:
- Better automation
- Happier users
- Safer deployments
