 Hello, everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate a scenario related to skill. Let's understand the required scenario first, and then I will be demonstrating how you can implement it. So in front of you, you can see the requirement. So we need to create and contact or opportunity records related to account based on user's choice. So through screen flow, we need to show two choices. It can be contact or opportunity if user selects contact. So and contact records should be created related to account. Otherwise, an opportunity should be created. So this scenario will help you to understand how to implement loop through decision element when collection variable is missing. So let's jump to developer edition org. So here you can see the flow screen is available. So from here, I can just click on new flow. I am selecting screen flow and clicking on create. So first of all, I need to create a screen where I can provide two choices as contact or opportunity. So and I'm just converting it into a free form screen flow. So layout, I'm selecting free form because I just need to manage the iteration of the loop by myself. So just dragging and dropping the screen. So label of screen will be object selection. From left hand side, I'm picking a component as pick list. So this pick list label will be select an object. It will be required. Now here I need to provide two choices. So I'm going to select choice because I need to manually create these choices for this pick list. So the API name is contact choice label that will be visible on the UI will be contact. And if you select contact, so at back end, we will be using this value as choice value that is contact clicking on done. Then I need to create one more choice. So this time API name will be opportunity choice label is opportunity choice value is opportunity and click on done. So this way two choices are available in this pick list. Now I'm clicking on done connecting it. Now after this, I need to apply a decision so that I can identify whether user selected contact or opportunity. So label of this decision is check object selection. Then we need to provide outcome details. So first outcome is is contact. And here I need to select this screen pick list component, which is selected object. If it is equals to contact. It means user selected contact as an option. Now second outcome will be is opportunity. Now again, I need to select the pick list if it is equals to opportunity. So it will match. So this way I have two outcomes one for contact and one for opportunity. Now I'm clicking on done. So this way I'm connecting it here. Right. So now based on the decision, like if you selected contact, so you need to go to contact path. If you selected opportunity, so you need to go to opportunity path. At both the paths, you need to iterate a loop. So for that, you need to receive the count of record as well. So what I'm going to do in this screen object selection, I am adding one more component that is number. And how many records will be the label. So here we need to receive how many records user want to create for that particular selected object. So that value will be available in this component. That is how many records and I'm clicking on done. Now I just need to iterate a loop. So I'm going to create one resource for loop counter. So it will be a variable and I'm naming it as counter. It will be of type number. Default value is one decimal places are zero. Right. So this counter variable will be starting from one and it will go to like how many records user want to create. So I created this. Now I'm going to have one more decision. Check counter counter is less than required records. So you can have counter then less than or equal and how many records. So if counter is less than this value, so it means your iteration will continue. So I'm connecting it. So it is for contact. Now after this, I need to place the screen to receive contact information. So here I'm going to place text for first name one more time text for last name. So it will be required. I'm clicking on done. So this way I'm connecting it right after receiving this information from user for this contact. I just need to add this information to a list where all the contact information will be available. So for that purpose, I just need to create two variables. So first time creating variable named as contact record, it will be of type record and object time selecting as contact. So what will happen, like whenever on screen, you will be providing contact first name and last name. So you need to store that information into a variable and that variable should be of type contact object. So that's why I'm creating this and here I'm not enabling this checkbox because it will be storing only one contact information. So I just clicked on done. I'm creating one more resource as variable. This time I'm creating it as contact list and I'm checking this checkbox. So this contact list will be storing more than one context together. So I clicked on done. Now from here, I need to use assignment. So I need to add contact information. So contact record dot first name equals first name. Then contact record dot last name equals last name. So this way this assignment is created. Now we need to link this contact report with account as well and account ID will be received through the UI. So we need to store it into a variable that is record ID. Data I will be text and available for input. So whenever you want to receive any value in terms of record ID, outside of the flow into the inside the flow. So for that purpose, you will be creating the code ID variable always. And here you can select contact record dot account ID equals record ID and done. So this way whatever information is available in this screen. So we assigned that into a single contact report. Now I need to add one more assignment so that I can assign that contact record to a list. So we have a contact list. So we need to add contact record into the list. Now one more thing that we need to do, we need to increase counter by one. Right. So I'm adding one into that counter variable, which is of type number and clicking on done. And from here I'm connecting it with this. So this way it is a loop. So through this decision counter will be checked whether it is less than that required report number or not. If it is less than, so this whole process will repeat after completion, like what we can do, we need to create records. So eight contacts, multiple contacts from this list. So I selected contact list and clicking on done and I'm connecting it here. So this way, first phase of this requirement is complete. Now I need to implement another phase. So I am just selecting decision, check counter for opportunity. If counter is less than or equals to how many records. So this process will be true. Well, it is same as we created it here. So I'm connecting it. So mostly the steps will be same, but that we need to do for opportunity. So after this decision, I need to create a screen where I will be receiving all opportunity information. First I'm having text. So text is for opportunity name. Then I'm having date so that we can store close date of opportunity making all required because all these fields are required. On opportunity. So name, close date and this pick list I chose so that I can have stages. So stage pick list is already available with opportunity objects. So I'm choosing pick list choice set and naming it as stays name. Object is opportunity, pick list and stays name and done. Right. So this way, this screen is ready. I can connect it. Now I need to create two resources as variable so that I can assign this information into opportunity record. So as we created variables for contact, we are creating it for opportunity. Sorry. It should be opportunity record and record opportunity done. I'm creating one more variable opportunity list record opportunity. I'm checking this checkbox allow multiple values and now I need to create two assignments. So having first assignment, so assign opportunity info. So opportunity record dot name equals name. So we have this name screen component. Then opportunity record dot close date equals close date. Then opportunity record dot stage equals states. So states we created as a pick list choice set, but we need to select the screen component because the selected value will be available with this screen component pick list. And then we need to link this opportunity record with account. So I'm going to populate account ID with the record ID variable that we created and done. Right. Now one more assignment. So assign opportunity part to list. So OPP list add OPP record. And we need to increase counter by one. So counter add one. So this way this part of iteration is also implemented. Right. So if I place it like this, right. So you can see above we have a loop for contact below we have a loop for opportunity. Now I'm going to have this create record element. So it will be creating opportunities, multiple opportunities and from opportunity list. So I'm clicking on done and connecting this right. Right. So whenever this decision will be false, it means this loop will break. Like it won't iterate anymore because the number of records are already available or added to the list. And after the condition when the condition is false, we can just create the records. Right. So this way I hope you understood how we can implement the requirement which I discussed in the beginning. Now I am just saving it. So create and contact or opportunity on account. I am clicking on save. Activate now moving to accounts tab create opening account report and clicking on gear icon added page. So now we are going to place this screen flow on the account report page so that we can test it. So I'm just removing this flow that was already there and I'm going to drag and drop it and from right hand side, I'm going to select that flow. So create and contact or opportunity on account. Then we need to enable this checkbox so that account ID will be passed automatically and then save go back and now your flow is ready to pass the values. So first of all, I am selecting contact. So at left hand side, you can see there is no contact. So I'm going to create two contacts clicking on next. So first contact. So on one on one then on two on two next. So at left hand side, you can see two contacts are created. Now if I select opportunity, again, I'm going to create two opportunities and you can see four opportunities are already there. Okay. So it is not working as expected. So we need to check what is not working for opportunity. Okay. So mistakenly I use greater than or equal, but I need to use less than or equals. So I'm clicking on done service. Sorry, save as and I'm creating a new version of it, saving it. So here you can see we are on version two. So it is saved. I'm activating it. Now I just need to refresh the space. I don't need to replace the flow. It is already added. So I'm having opportunity, entering how many records as two clicking on next. So this time you can see I can enter the opportunity information as well. So OPP 301 close date stays next and OPP 302 close date and stays and next. So at left hand side, you can see now we have total six opportunities. So this way I hope you understood how we can implement the scenario where user is selecting which objects, how many records that user wants to create. Thank you.