Use Case: Simple Loop 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:Use Counter When (See Example):
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 Loop example!

Lulu Mobile uses the standard Opportunity and Opportunity Contact Role objects to track their deals. When they are selling family packages, they will list all the family members as Opportunity Contacts. To make sure each member is on board with the plan, they need to reach out to all contacts listed on the opportunity. Thus, they want to have a quick action that will generate one task per contact. Also, The sales reps should be able to decide when to generate the tasks.

We can easily get all the Opportunity Contact Role records into a collection, and we need to generate a task for each contact which is a dynamic action. Thus, we will use Loop.

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

Please wait while flipbook is loading. For more related info, FAQs and issues please refer to DearFlip WordPress Flipbook Plugin Help documentation.

Screen FlowAssignmentVariable/Collection
LoopGet RecordsInput Variable
Create RecordsRecord 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
Sarath

Thanks. Learning Flows. I am more worried about when started learning Flows. Gaining some confidence.