Loading
Automate Your Business Processes with Salesforce Flow
Test a Flow with Isolated Test Data

Test a Flow with Isolated Test Data

Test record-triggered and autolaunched flows using dedicated, reusable test data from an Apex class that includes a test setup method. After a test scenario runs, the isolated test data rolls back like an Apex unit test, so your org's live data stays as it was.

Required Editions

View supported editions.
User Permissions Needed
To open, edit, create, activate or deactivate a flow using all flow types, elements, and features available in Flow Builder, including Einstein and Agentforce for Flow: Manage Flow

When you use org data for testing, anyone can change that data and your tests can start to fail. Record IDs differ between sandbox and production, so tests that pass in one environment can fail when you deploy to another. Create isolated test data when the test scenario runs, just like Apex Test Setup creates data at run time. Your test data stays consistent so you can deploy it across environments.

To open a flow in Test Mode, see Set Up and Run a Test Scenario (Beta).

  1. Create an Apex class with the @isTest annotation and a @testSetup method that inserts the records you want available during the test scenario.

    For example, this Apex class creates test accounts. See Using Apex Test Setup Methods.

    @isTest
    global class CommonTestSetup {
      @testSetup
      global static void setup() {
        List<Account> accts = new List<Account>();
        for (Integer i = 1; i <= 2; i++) {
          accts.add(new Account(Name = 'Test Account ' + i));
        }
        insert accts;
      }
    }

    When using isolated test data that’s in a data silo, your input record must reference a record that you created in your isolated test data. If the record doesn't exist in that data, you receive an error. Unlike a test scenario that uses org data, you can't customize the field values of an input record in isolated test data from Flow Builder. The record is selected in the isolated test data by its key fields and used as-is. In your Apex @testSetup method, populate all key fields. You select key fields later in these steps.

  2. Open a record-triggered flow or autolaunched flow.
  3. Click Test to enter Test Mode (beta).
  4. Turn on Scenario Testing Automation, then for Select Data Source, select Run from Data Silo.
    The required Apex Test Setup field shows. Select the Apex @testSetup class that you created. The test scenario uses the Apex class as the data source, with rollback so your org data stays unchanged.
    Run from Data Source option
  5. Select the key fields for each object used in the test scenario.
    The isolated object external key fields identify unique records in the isolated test data. Because test record IDs change after every run, these key fields match input records to the isolated test data at run time. For example, use the Phone field as the key field to identify account records.
    The Set Up Unique Records tab to select key fields
  6. Set the triggering record or input values to match a record in your isolated test data.
  7. For Expected Results (Assertions), configure any assertions, then click Save Scenario and Run Scenario.
    The test scenario runs against the isolated test data in the data silo, instead of your live org data.
 
Laster
Salesforce Help | Article