Loading
Salesforce now sends email only from verified domains. Read More
Automate Your Business Processes
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Automatically Test Record-Triggered, Autolaunched, and Data Cloud-Triggered Flows

          Automatically Test Record-Triggered, Autolaunched, and Data Cloud-Triggered Flows

          Before you activate a flow, test it to verify expected results and identify run-time failures. Use automated flow testing for record-triggered, autolaunched, and Data Cloud-triggered flows.

          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
          To view test run details in Flow Builder: View All Data

          Automated testing for flows saves you time and improves the flow's reliability. When you debug a flow, you manually configure the debug parameters and inputs each time you start to debug. With a flow test, you configure the test parameters and inputs one time. Each time you run the test, it uses the same configuration to evaluate the flow. Also, you're not stuck with the same test per flow. You can edit the test or create more tests for different scenarios.

          We recommend that you create a test for every path that the flow can take. A flow test runs for the active flow version. If a flow version isn't active, the flow test runs for the latest flow version.

          Test a Flow

          In Flow Builder, you can create, save, and run automated flow tests for record-triggered, autolaunched, and Data Cloud-triggered flows. You can optionally use isolated test data, so tests don't affect org data. Each time you modify the flow, you can run the test.

          We recommend that you test all possible paths through the flow so that you can find errors before they affect your users. For example, if users or inputs don't provide all the data that your flow requires, the flow fails. Add fault connectors to provide paths for users or the flow logic to correct the data so that the flow can finish successfully.

          1. Open the Flows list view.
            • From Setup, in the Quick Find box, enter Flows, and then select Flows.
            • From the Automation app, select the Flows tab.
            • From the Flows tab in any Lightning app, click the actions menu and select Open Flow.
          2. Open the flow version that you want to test.
            • From the flow list screen in Setup, click Actions menu icon for the flow that you want to test, select View Details and Versions, and then click Open.
            • From the flow list screen in the Automation or any Lightning app, click the flow's Related tab. For the flow version that you want to test, click Actions menu icon, and then select Open Flow.
          3. Click View Tests, and then click Create.
          4. In the Set the Test Details, Trigger, and Path window, configure the test.
            1. Enter a label, API name, and description for the test.
            2. For Run the Test When a Record Is, select Created or Updated.
            3. For Flow Versions to Test, add the flow versions to the Selected Flow Versions column.
              The flow test runs for the flow version that’s currently open in Flow Builder. The flow test is available for each of the selected flow versions.
              The New Test window of a record-triggered flow
          5. To use isolated test data for record-triggered and autolaunched flows, click Test Setup, select Run from Data Silo, and select an existing Apex test class that has a @testSetup method.
            Before you create the flow test, create and deploy an Apex class with a test setup method that inserts the records you want available during the test. If you don’t see any Apex classes, you don’t have an Apex class with a test setup method. See the Test Flows with Isolated Test Data section. Isolated test data is available for record-triggered and autolaunched flows.
          6. For autolaunched flows, click Set Test Input Values, and set the values for each input variable, such as, record, text, or number.
          7. For record-triggered and Data Cloud-triggered flows, click Set Initial Triggering Record, and enter the values for the record that initially triggers the test.
          8. If an updated record triggers the test to run, click Set Updated Trigger Record, and then enter the record values.
          9. Click Set Assertions, and set conditions and custom failure messages for each assertion.
          10. Save your changes, and then click View Tests.
            The owner of the flow changes to the last person who edits the test.
          11. Select the test that you configured, and then click Run.
            Flow Builder runs the test and shows the result in the Result column.

          Test Flows with Isolated Test Data

          Run flow tests for record-triggered and autolaunched flows using dedicated, reusable test data from an Apex class that includes a test setup method. After the run ends, the test rolls back like an Apex unit test, so your org’s live data stays as it was.

          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 runs, just like Apex Test Setup creates data at run time. Your flow test data stays consistent so you can deploy it across environments.

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

            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;
              }
            }

            You can't test a flow where no matching record exists in the isolated test data. Because an input record must reference a record that already exists in the isoloated test data, you can't test a record-not-found path with this data source. Unlike tests that use org data, you can’t customize the field values of an input record in isolated test data. 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. In Flow Builder, open the flow and click View Tests, then click Create, or edit an existing flow test.
          3. Click Test Setup, select Run from Data Silo, and select the Apex test class you created.
            The flow test uses the Apex class as the data source. The test uses isolated test data with rollback so your org data stays unchanged.
            Run from Data Source option
          4. Select the key fields for each object used in the test.
            The isolated object external key fields identify unique records in the isolated test data. Because test record IDs change after every execution, these key fields match input records to the isolated test data at test 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
          5. Set the input variable values in the isolated test data.
          6. Set assertions and any other test details, then save and run the flow test.
            The flow test runs against the isolated test data in the data silo, not live org data.

          Test a Flow for Error Handling

          Configure negative assertions in a flow test that intentionally test flow paths where things don't go according to plan, making sure that your flows handle errors gracefully.

          Configure negative assertions for Create Records, Update Records, Delete Records, and Action elements in a record-triggered, autolaunched, or Data Cloud-triggered flow.

          1. Create a flow test.
          2. When you set assertions, select a resource for Create Records, Update Records, Delete Records, or Action elements.
          3. For Operator, select Has Error.
          4. Select a value, and save the flow test.
          The flow test assertion that shows the selected Has Error operator
          Example
          Example

          Consider a flow that processes customer data. You can create a test to make sure that the flow handles invalid input, such as a missing required field.

          Interpret Flow Test Results

          Understand how to interpret the flow test results after the flow test run completes.

          We recommend interpreting the results after testing a flow to make sure that the flow operates as intended under various conditions. When you use isolated test data, the test run details show the same assertion and path information. The test ran against isolated test data rather than org data.

          1. To view the test run details, click Actions menu icon, and select Run Test and View Details.
            The All Details tab under Test Run Details shows the results for the entire test run. If a flow fails, troubleshoot the flow errors.
          2. To check the status of the flow tests, under Test Run Details, select the Assertions tab, and then expand each assertion.
            Test run details of a record-triggered flow
            The Flow Builder highlights the path of the test run (1). In the Test Run Details, each assertion tells you what condition it was looking for (2), the values that those conditions were checked against (in parentheses) (3), and the custom error message that you defined for that assertion (4).
          3. Interpret the failed flow test.
            1. Check the condition and the condition evaluation of the failed assertion.
              In this example, for the Set Priority to High element, the failed assertion looks for the value of the field $Record’s Priority to be set to High.
            2. To change the value, click the element, and then click Edit Element.
              In this example, to fix the failed assertion, edit the Set Priority to High element and change the priority for $Record to High.
            3. Save the flow, and then run the flow test that failed.
          Example
          Example

          This test verifies the flow when an object is updated and the flow takes the path that runs immediately.

          The New Test window with sample test configurations.

          The test includes fields to set the initial and updated values for the triggering record, which is the same record that triggers the flow to run. The test creates a copy of the record to use only for the test. The record isn’t saved to the database.

          The test evaluates each assertion to verify that the flow runs as expected. A test can evaluate only whether a flow element was executed and whether flow resource values are set as expected. The test evaluates the flow based on the existing data in your Salesforce database and customizations, such as rules and restrictions.

          The Set Assertions section, showing the assertions and their values

          When a flow includes tests, the Tests list view shows all tests for a flow and associated test results.

          The Tests list view, showing the created tests

          After a test is run, Test Run Details shows how each assertion was evaluated. If a condition evaluates to false, the assertion and test fail. If all assertions pass, the test passes.

          The Flow Builder, showing the Assertions tab under Test Run Details

          The All Details tab shows the results for the entire test run. Assertions are evaluated at the end of the test run.

          The Test Run Details section, showing the All Details tab

          When you’re confident that your flow is working as expected, activate the version that you tested and distribute the flow.

          Flow Test Limits and Limitations

          Understand how many tests you can create per flow and the limitations of a flow test.

          Limits

          The maximum number of tests per flow is 200.

          Limitations

          • Flow tests are available for record-triggered, autolaunched, and Data Cloud-triggered flows.
          • Isolated test data is available for record-triggered and autolaunched flows.
          • Flow tests for autolaunched flows aren’t supported for flows that include callouts or wait elements.
          • Flow tests don’t support flows that run when a record is deleted.
          • Flow tests don’t support flow paths that run asynchronously.
          • Flow tests don't count towards flow test-coverage requirements.
          • Formulas aren't supported for setting test data. Use fixed values. For example, if a flow test that verifies a date field is set to the relative date Today, you must update the field manually before running the test. For example, if you create and run the test on August 3, 2022, the date is set to the relative date August 3, 2022. If you run the same test tomorrow, the value of the date field is still August 3, 2022.
           
          Loading
          Salesforce Help | Article