Flow: How To Use “Counter”

Continue from the Loop article, here we would like to introduce how you can repeat the same actions for a specific number of times by using “Counter” in flow.

Counter is not an out-of-the-box functionality, rather it is more of a foundemental tool of all programming languages. The concept is very easy – you create a variable, and use it to track how many repetitions have been run. Let’s dive into the steps of how to achieve that.

Step 1 – Create a number variable

First you need to have a number variable, call it Counter, and set the default value to 0.

Flow counter - step 1
Step 2 – Create Decision element to set the breaking point

To tell the system when to break the repetitions, we need to add a Decision element. Then you set two outcomes and use the goal number to separate the two. For example, if we want to run it 10 times, the first outcome would be when the counter is < 10, and the second outcome is counter >= 10.

Flow counter - step 2
Step 3 – Add actions inside the loop

After having the Decision, add actions that will run in each repetition, and connect with the first outcome that we created. (When counter has not reahced our goal). Remeber to move the add to collection action to another assignment! (Here is just to demonstrate they are a set of actions)

Step 4 – IMPORTANT! Edit the counter using Assignment

As the counter is an ad-hoc variable that we created, we have to let the system know once a repetition is done running. To achieve that, use an Assignment element to modify the counter, namely add 1 to the counter. By doing so, the counter can now track how many repetitions have been run.

*** NOTE: You can move the add to collection action from the previous assignment to this assignment.

Flow counter - step 4
Step 5 – IMPORTANT! Close the loop

Same as Loop element, you will also need to close the loop manually when using Counter.

Flow counter - step 5
Step 6 – Add actions after the loop is done

If you want to continue your flow after all the repetitions are done, add the elements and connect with the second outcome. (When the counter is over the goal)

Flow counter - step 6

Then we finish with how Counter should be set up and utilized!

Check Out How Counter Can Be Used In Real Cases!
Use Case: Simple Counter Example in Flow
Earlier we have published the how-to guides on Loop and ...
Read More
Use Case: Auto-Generate Multiple Lines Of Opportunity Product
* Updated at Mar. 25, 2021. The original flow is ...
Read More

Official Salesforce Help Article On Loop

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments