+ Start a Discussion
huskerwendyhuskerwendy 

Flow design help - using Loop logic to loop and create records until loop counter is reached

I need help determining the logic to use in my flow. Basically, I want to call a flow from process builder that will create new records based on the value passed in from the process builder. We have a custom obejct (transaction) and a new records is created, if the frequency of the parent object of the transaction is "Annual", I need the flow to create 11 additional records with the date for each record equal to the first day of the next 11 months. If the frequency is "Quarterly", I need the flow to create 2 additional records with date equal to the first day of the next two months. If the Frequency is "Semiannual", I need the flow to create 5 additional records with the date of each one equal to the first day of the next 5 months. 

Is this somethig flow can do? My plan was to create a counter based on the frequency and then loop until the frequency counter is reached. However, I can't seem to figure out how to loop through anything other then a Salesforce object. However in this case the objects don't exist yet. 
Best Answer chosen by huskerwendy
huskerwendyhuskerwendy
I figured it out. I didn't actually need to use the Loop logic. I used assignment and decision logic to increment a counter. I changed the deicison logic for the number of records to create to input variables and am passing them in to the flow as a record count variable from the process builder.

User-added image

LoopCounter increment
User-added image

Check Loop Counter
User-added image

 

All Answers

pankul guptapankul gupta
Please find the below link for the same how to create bulk records via a Flow:

https://help.salesforce.com/articleView?id=vpm_records_create.htm&type=5
 
huskerwendyhuskerwendy
Hi Pankul,

Thanks for you response. I understand how to create new records. What I don't understand is how to loop through a record set that is not an sObject. I've attached an image of my flow. However, it's not actually working. I don't think my loop is correct.

User-added image

here's my loop definition
User-added image

Here's my record count assignment
User-added image
huskerwendyhuskerwendy
I figured it out. I didn't actually need to use the Loop logic. I used assignment and decision logic to increment a counter. I changed the deicison logic for the number of records to create to input variables and am passing them in to the flow as a record count variable from the process builder.

User-added image

LoopCounter increment
User-added image

Check Loop Counter
User-added image

 
This was selected as the best answer
Roy_ARRoy_AR
Since Winter 18, an exciting new feature has hit the tables, which makes it so easy, to deal with loops while working in visual flows. 
 
Now looping through a collection of records, incrementing the counters is no longer needed. 
Instead the record count can be easily fetched in a sobject collection variable and assigned to a number variable. Play around with the count variable directly. So finding out the number of open/closed/in progress opportunities gets more easy. I can think of many more use cases that will be benefitted because of this feature.
 
So to answer this question, all you simply need to do is like:
1. Perform a fast lookup with your required filters
User-added image
2. Assign the record count to a sObject collections variable. (in screenshot: nofCases)
3. Use a Assignment step, to assign the variable to a number variable. (Point to note: the assignment variable should be of type number only to make use of equals count operator. In the screenshot, this is called testCount)
User-added image
4. Voila! Now play the hell around with the assigned variable :)

If this helped anyone here, dont forget to hit the thumbs up.

Cheers!!
Roy