Image of Nadina Lisbon next to text that says, "Automate This! — Test and Debug Record-Triggered Flows with Nadina Lisbon".

Automate This! — Test and Debug Record-Triggered Flows with Nadina Lisbon

By

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by #AwesomeAdmin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, four community Flow experts showcase a Flow feature you can use in record-triggered flows. This blog post covers the flow testing feature Nadina Lisbon showcased during the episode.

Gone are the days of only being able to debug your record-triggered flows manually. With the Summer ’22 Release, you can now write Automated Tests! Currently, flow tests only support flow paths that run immediately.

Note: This feature is a Beta Service, which means customers may opt to try this feature at your sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

Why do we test?

As we continue to build more and more record-triggered flows, it’s important to ensure that they work as expected. Being able to automate testing will not only save us time but also improve the quality of our record-triggered flows. Previously, we would run the record-triggered flow, then retroactively fix the errors as we debugged. Now, we have more control as we can test our functionality upfront, giving us Flownatics MOAR time to create even MOAR flows!

What are we testing?

Before we dive into our testing, let’s quickly talk about the record-triggered flow we need to test. Below, I have a record-triggered flow that does the following:

  • Based on the Customer Priority
    • When the Customer Priority is set to High
      • Post To Chatter
    • When the Customer Priority is set to Medium
      • Change the Rating to Warm

The view of the completed record-triggered flow.

Types of tests and test cases

As we think about our testing outcomes, it’s important to write different test types. We’ll focus on positive and negative tests.

A positive test returns the results we’re expecting. A negative test is used to test how our flow handles invalid or unexpected data. With our given scenario, here are our test cases:

Positive test

  • When the Customer Priority is set to High
    • Assertion: A Chatter FeedItem is created
  • When the Customer Priority is set to Medium
    • Assertion: Account Rating will equal Warm

Negative test

  • When the Customer Priority is set to Low
    • Assertion: Chatter FeedItem is not created
    • Assertion: Account Rating does not change

Note: We can create 200 tests per a given flow.

Setup

Now that we know what we want to test, let’s get started! To view test run details, you need the View All Data permission. Note: You can view test results and run tests without the View All Data permission.

First, we’ll access the test area by clicking View Test (Beta).

The View Test (Beta) button highlighted in Flow Builder.

This will bring us to the Tests page where we’ll click Create.

Tests page with Create button being selected.

Since this is our first test for the flow, we’ll automatically be directed to the New Test page.

The Set Test Details, Trigger, and Path tab on the initial page to configure a flow test.

Here’s where the magic begins! Let’s start with our positive test. Specifically, let’s create the test case for when the Customer Priority field is set to High.

Set Attributes as the following:

  • Label: Customer Priority High
  • API Name: Account_Create_Customer_Priority_High (This will be automatically generated once the label is filled.)
  • Description: Test when the Customer Priority is set to High

Given that our flow is only for Create, we’ll leave the Run the Test When a Record Is value as Created.

Set Test Details, Trigger, and Path tab showing Created highlighted as the way to run the test.

Next, we’ll set the data for the record in the Set Initial Triggering Record tab. Instead of inputting data, I’ll use the account record called “Burlington Textiles Corp of America” that’s already set up in my org. I’ll change the Customer Priority field to High and click the Set Assertions tab.

Set Initial Triggering Record tab showing the Customer Priority field set to High.

Now, we’ll create an assertion to test that we posted to Chatter correctly. To do this, we need to check that a FeedItem record was created properly.

On the Set Assertions tab, we’ll click Save.

Set Assertions tab showing the configured assertion for the Chatter feed item.

Now, let’s run our test.

Hooray! Our test was successful.

Test results with the Assertion items highlighted.

Let’s create our last positive test, where the Customer Priority field is set to Medium.

  • Label: Customer Priority Medium
  • API Name: Account_Create_Customer_Priority_Medium (This will be automatically generated once the label is filled.)
  • Description: Test when the Customer Priority is set to Medium

Set Test Details, Trigger, and Path tab showing the Created option selected.

Again, we’ll use our Burlington Textiles Corp of America account and change the Customer Priority field to Medium. Next, we’ll click the Set Assertions tab.

Set Initial Triggering Record tab showing that Customer Priority is set to Medium.

For this assertion, we’ll test that our field updated correctly, so we want to check that Account Rating is now Warm.

Set Assertions tab selected to check that the account rating is Warm.

Finally, we run our test and can see that when the Customer Priority was set to Medium, the Account Rating updated to Warm.

Test results with the Assertion items highlighted.

Now, let’s do our negative test.

  • Label: Customer Priority Low
  • API Name: Account_Create_Customer_Priority_Low (This will be automatically generated once the label is filled.)
  • Description: Test when the Customer Priority is set to Low

Set Test Details, Trigger, and Path tab with the Created option selected.

We set the Customer Priority field to Low and click the Set Assertions tab.

Set Initial Triggering Record tab showing the Customer Priority field is set to Low.

This time, we’ll have two assertions. We want to check that our FeedItem record was not created and that the Account Rating was not changed. We’re doing this since this is our Default path in the flow, so we’re asserting the default outcome within our decision was performed.

Set Assertions tab showing that there’s no Chatter feed item and that the Account Rating has not changed.

After running our test, we can see it’s behaving as expected.

Test results with the Assertion items highlighted.

Let’s recap

And with that, we’ve successfully tested our record-triggered flow! Here are some of the key takeaways from this post:

  • The maximum number of tests per flow is 200.
  • Flow tests support only flow paths that run immediately.
  • To view test run details, you need the View All Data permission.

Happy testing!

Resources

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Use Flows and Experience Cloud to Access Salesforce Scheduler.

Use Flows and Experience Cloud to Access Salesforce Scheduler | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Lynn Guyer requests support from […]

READ MORE