EP - 27 | HOW TO TEST FLOWS | Lightning Flow Series⚡️

 


VIEW TEST

In this blog you will learn about a feature that salesforce introduced in Summer'22 release that is "View Tests". This option is available to test the Record-Trigger Flows.

What is this option used for?

With this option we can create tests for our flow and check all the conditions before activating the flow.
We recommend that you test all possible paths through the flow, so that you can find errors before they affect your users.


Where we can find this option?

For testing flows go to Setup > Flows > Your Flow > On top right corner you will find a button "View Tests".

Have a Look : 

In this example I have a flow with the following details :
  1. Flow will fire when an Account is created.
  2. Check if the account name is "Monika".
  3. Create a case for that Account.

Here is the flow :

Now, let's learn how to create and test TESTS.

So, just like apex test class for one class you can create multiple conditions to check if your class will pass all of those or not. Same as that here you will create a test, add a record which will fire the flow and the test, add assertions(Conditions) to the test.

To create a test for your flow, click on the "View Tests" Button and this is how the window will look like :

You will have three options here which are mandatory.

1. Set Test Details, Trigger and Path - In this option you will give your test a name. After that it will ask Run the Test When a Record Is : here you will have to choose created or updated.
Note : if you have chosen "a record is created" then in this option "Created" will be selected automatically.

2. Set Initial Triggering Record - In this option you will set a intial test data or test record which will fire this flow. In our case it will ask us to add an Account because this flow will fire when an Account will be created.

Have a Look : 


When you will add an account, All the account details will automatically fill up.

3. Set Assertions - In this options you can set as many conditions you want to add to check your flow.

Have a look :


You have to add at least one assertion to a test. In this add the resource name and add the condition. You can also add a custom failure message in case of assertion fail.
After that click on save and your Test will be created.
The next screen will look like this :


Here you will see the list of tests that you have created. You can select the Tests you want to run and click on the run button below.

After you run the test the screen will look like this :


It will show you the result and to check the details by assertion click on the arrow and select "Run test and view details".

I have shown three scenarios in this example.
1. In this condition above we are checking if the name is Monika. For that we are taking a Decision Element and in that we have taken a variable "accname" and in Default value we added "Monika".
Now, for this assertion we will change the "accname" variable value to "Abella".

Have a look :


Now, Let's run and this assertion should fail because we changed the name and flow will give error.


Here, it will show you Assertion 1 and you can see your custom failure message here as well.

Now, let's try the second condition.
In second condition we will add "accname" equals to "Monika". So, this should pass right?
Have a look :



Here is the result :


First one fails as expected. But, 
wait a minute. 
What happens to the second one? 😰
This was correct right?

So, here is the thing. If your first assertion will fail the second one will not even be evaluated. Only if one condition passes then the test run will shift to the next one in the row. 
why this?
So that you can correct your flow step by step and find out what is wrong.

Now, let's do the last condition. In this we will switch the names. In the first assertion we will add "Monika" and in the second one we will write "Abella".

Have a look :


Here is the result :


Because the first assertion was correct it went to the second one. 
The second one was wrong and it failed.

That's how you can set assertions to check all the possible conditions for your flow before anybody else finds out.

Hope you found this blog post useful.
For detail video tutorial go to this video below :



If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Let's learn and grow together.
Love and Peace! 

Post a Comment

0 Comments