 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate you how you can create a loop using decision element in flow when you don't have collection variables. So in real time, like if you want to create a loop in flows, so we basically create those on collection variables, but in case if you don't have collection variable, still you want to make a loop. So we can do that using decision element. So I'm going to demonstrate you how you can do that. So the use case will be, we are going to create multiple contacts on account using screen flow. So on account there will be a screen flow which will ask, like how many contacts you want to create and then by iterating a loop, we will be receiving first name, last name or other fields related to contact one by one and together all those contacts will be created on account. So before starting this demonstration, let me tell you my website, StudySalesForce.com. So if you visit this website, so here you can find various topics on which I pasted all the links here. So if you go to flow, so all the flow related video links are available here, so you can watch them. Now coming back to this use case, so I'm going to set up and first I will be creating the flow and then I will be placing this flow on account record page so that we can test it. So I'm creating new flow. So we are going to ask from user like how many contacts we want to create. So that's why I'm using screen flow. The user will be telling like how many contacts they want to create. So this is a screen flow builder. So here, first I'm going to put the screen so that I can read how many contacts they want to create. So let's say I am putting number. So this label will be displayed how many contacts and I'm putting its label API as screen one done. So this is a screen one, which will be receiving number of contacts that you want to create. Then I'm going to create one resource as a record ID. So the current record ID, we want to fetch like we will be placing this screen flow on account record page so whatever account you you will be opening currently so you want to fetch ID of that account. So that will be automatically available into into this record ID variable. So remember that here this I is capital and others are small. And its data type will be text. And you need to mark this as available for input because this variable will be receiving input from outside this flow. So this record ID variable is created. And here we have this quantity in this screen flow component. So I need to create one more resource variable as counter. Its data type will be number. Its default value will be zero. So this variable counter variable I'm going to use to iterate a loop so that we can identify like how many times we want to iterate the loop. I'm going to create a decision. Check counter. So so its label will be so first branch of this condition will be did we finish creating contact. So putting it as yes. So counter greater than number so this how many contact this is a screen component so if counter is greater than this number of contact it means we finish creating contact. Then I'm going to create one more. In this case, counter is less or equal to how many contact right. So we started that from zero so I think here we should put less than and here we should put equals because default value of this counter variable is zero that's why if it is equals to how many contact then it will be terminated otherwise it will be depicting. So, now, inside this condition, I need to put one more screen where I will be receiving first name last name of the user, like for contact creation, so it will be for first name required, but more time text. It will be for last name required. Label of screen is screen two. So it is created. So I'm choosing no. So, if this condition is matching like did we finish creating context so no, then it will be asking first name last name. Now I need to create two more resources. So first variable contact record data type will be record object will be contact right and I'm not selecting this so it will be storing details of one contact only. Now I need one more resource. So it will be a contact list. So one by one I will be creating contact record and I will be adding those contact into this list so that all together I can insert those contacts. So here I have checked this checkbox. So this will be a collection variable. Right, so now I'm going to use this assignment. So I'm contact values. So here I'm putting I'm choosing this contact record dot first name equals first name that is available in screen as a screen component and again contact record or last name equals last name screen component and we need to link this contact with account. So, as I told you earlier, like we created one more variable as a record ID that will automatically receive the current account record ID. So, it will be equals to record ID. Right, so this way one contact will be created then it is linked with this again assignment. So add contact list. So here I'm going to put this contact list dot add and contact record. Right. And one more assignment so that we can increase the counter. So, please counter. So counter. Add one. So this will be incremented by one, then link it here so this way it will be a loop and after or what we can say when this condition will be in this state, did we finish creating contact. So it means yes so in that case we need to create the records. Contacts multiple and here we can put contact list. And it will be when this is occurred. Right, so this way it is a loop when this condition will be in this branch. So all the contact records will be created automatically under a particular account. So this way you can see I did not I did not use this loop element and using decision assignment only I created a loop kind of thing on numbers so I'm going to save this create contacts. I'm saving this. Okay, so I need to save it with another name. Contacts of account saving this activating now I'm moving to account clicking on edit page so that I can place this flow on a countercard and automatically account ID will be passed. So, on which account you want to create multiple contacts that account ID will be passed to flow and automatically you can start that flow put the required number of contact that was that you want to create. And provide first name last name and then you will see those contacts will be created automatically so name of our flow is create many contacts on account. Here pass record ID into this variable so we created this variable and we allowed it as like available for input so that's why it is available here. So this way I'm clicking on save. It is safe moving back to account. So, let's first check how many contacts are related to this account. So here you can see only one contact is associated and here you can see this flow is available so I'm putting to next. So first name, let's say Sanjay Gupta. It is asking one more names I'm typing because of the. So you can see it only asked twice to contact names and here you can see two contacts are linked automatically here. So this way if you receive any number and you want to iterate that number as a loop inside flow. So this way you can implement your loop without using loop element and using assignment element on numbers. So sometimes in real time scenarios you will find this case like you don't have any collection variable to implement loop in flow. Instead you have any number and using that number you want to iterate a loop inside the flow. So you can do that how I implemented the scenario in this video. So I hope you understood how to create a loop using decision element and flow when you don't have collection variables. Right, so if you want to watch more sales force related videos you can visit this website. I hope you understood whatever I demonstrated in this video. Thank you for watching this video.