Create automated tests for triggered Salesforce flows

Telegram logo Join our Telegram Channel

Hello, Salesforce freaks out there! I am a hardcore developer at the same time I enjoy the power of low-code automation tools like Salesforce Flows. 

The triggered ones are my favorite! Testing these flows was a big challenge and manual task before. But not anymore, now you can automate the testing for your triggered flows.

Note: Only record triggered flows support tests as of Winter 2023.

Let us see it in action!


Example Use Case

I have created a simple flow on Contact to populate the standard MailingCountry field from Account. Basically, it copies the Account's BillingCountry value into the MailingCountry field on the contact.

This is a before-save flow, which uses one condition and one assignment element.

Example Salesforce flow for testing

Test Cases

Before we jump directly into the testing, we need to decide on the test cases. Like, as what behavior we need to test and what is the expected outcome.

To keep it simple I propose two simple test cases.

  1. Positive Test Case
    • Account is selected
    • MailingCountry is not present on the contact
  2. Negative Test Case
    • MailingCountry is present on contact so we don't need to update the value from the flow.

Create Tests for Triggered Salesforce Flow

Now that we know what to be tested let us create the tests.

  1. Open the flow you want to test in the flow builder.
  2. Click on the View Tests button from the top right side. There you can create new flows and see the existing ones.
  3. Click Create to create a new test. Enter the Label and Description for your flow.
  4. Just below the Description box (green highlighted box in the below image), you can select when you want to run the flow.

    Here you can select what operation to test, like record Created, record Updated, Run Immediately or Time Triggered

    Select options as per your need, I will select Created and Run Immediately.Select the path to test flow
  5. Click on the Set Initial Triggering Record section from the left sidebar and create the record for testing. Also, populate required lookups/mater fields if required.
    Create/Select test record to test flow
  6. The last step is to set assertions. You can set one or more as per your requirement. For the demo purpose, I will select only one to check if the MailingCountry field is populated or not.
    Set assertions for flow test
  7. Now it's time to run the tests.
    Run flow tests
  8. Once ran you can see the results of the tests if they passed or failed.
It's always a best practice to create both positive and negative tests. So go and create some awesome tests for your flows. Hope you liked this!

No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at