Use Case: Simple Counter Example in Flow

Earlier we have published the how-to guides on Loop and Counter, but they focus more on the setup instead of providing a complete use case and a step-by-step walkthrough. So today we are posting a simple example of using Loop and Counter in flow, and how to decide which one to use.

Summary

Use Loop When (See Example):Use Counter When:
Should actions work on different records?
Is there a Collection Variable?

Loop and Counter are both for executing the same set of actions multiple times. The only difference is that Loop will take in a collection variable, unpack it, and do the actions for each iteration either statically or dynamically. For example, if you have 10 items in a collection, the loop will run for 10 iterations. Dynamic ations mean that you need some field values from the current item, like case number, date, etc, while static actions mean you do not need those at all.

Counter on the other hand can only execute static actions. Furthermore, it is not an out-of-the-box functionality, so the performance might not be as optimal as Loop.

So a very simple way to decide which to use is by asking “Can I get a collection variable in any way?“. If yes, use Loop. If not, use Counter.

Let’s loop at the Counter example!

Lulu Mobile uses the standard Opportunity object to track their deals. In addition to Close Date, they have another field called Start Date as they want to track how long an opportunity has been in a pipeline. In order to win the deals, they want to generate one task per day in between the start and close date so the sales reps will remember to follow up. Also, the sales reps should be able to decide when to generate the tasks.

Since cannot get the interval of two dates into a collection in an easy way, we will use Counter. In general, Counter can be in any format as long as it helps us track the current iteration and set a stopping point. For example, you can have a number variable starting from 1 and adding 1 per iteration, and stops when the number reaches 10. Or, you can have a date adding 1 day per iteration, and stops when reaching a specific date. Since the system has to evaluate if now is the stopping point, a Decision Element is always needed.
We have the start date and close date in the example, so the start date will be our counter variable.

We will launch the solution as an Action. In order to use flows in Action, we will build a Screen Flow.

Screen FlowAssignmentVariable/Collection
CounterCreate RecordsInput Variable
DecisionRecord Id

Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!

Official Salesforce Help Article On Flow

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lae

Thank you!

Sabine

Thank you so much! Your website is great!