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.
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.
- Positive Test Case
- Account is selected
MailingCountryis not present on the contact- 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.
- Open the flow you want to test in the flow builder.
-
Click on the
View Testsbutton from the top right side. There you can create new flows and see the existing ones. -
Click
Createto create a new test. Enter theLabelandDescriptionfor your flow. -
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 recordCreated, recordUpdated,Run ImmediatelyorTime Triggered.
Select options as per your need, I will selectCreatedandRun Immediately.
-
Click on the
Set Initial Triggering Recordsection from the left sidebar and create the record for testing. Also, populate required lookups/mater fields if required. -
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
MailingCountryfield is populated or not. - Now it's time to run the tests.
- Once ran you can see the results of the tests if they passed or failed.





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 rahul@forcetrails.com