 Hello friends. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate the use of subflow element that is available in Salesforce Lightning Flow. If you want to watch more Salesforce training videos, you can search my name Sanjay Gupta on YouTube and you can watch various playlist and so you can watch various playlist related to Salesforce and other programming languages on my YouTube channel. So do follow it. So to implement this scenario, I have already created two subflows in form of normal flow. So subflow is nothing, it is an independent flow that you can merge with a particular flow. So in this video, you will see I will be creating three flows and I will be using two flows as subflow in third flow. So this is my first flow, that is to create opportunity record and you can see it is having two screens. So first screen will be receiving opportunity name and space and second will be receiving closed date. Right. And through this create record element, I'm going to create opportunity record and this opportunity record will be associated with account. So I am going to receive a record ID as input. So I created a variable for that. So this way opportunity will be created so you can use this lightning flow independently as well as you can use it as a subflow. Then this is another flow, which is to create contact. So on contact required field is last name. So I'm using that only. And this is a create contact record component or you can say element. So it is also having record ID variable. So it will be associated with account automatically and last name will be assigned to last name field. So this way I created these two independent flows that you can use independently as well as you can use them as a subflow. So I already demonstrated how I created these in my playlist that is available on my YouTube channel. So if you want to watch them, you can search those playlist related to lightning flow in my YouTube channel and you can watch how I created these. Now, after showing these two flows, I'm going to create third flow. And in that third flow, I will be using these two flows that is for opportunity creation and contact creation as a subflow. So I'm selecting screen flow. Now, here I'm going to create one more flow that will be calling those two flows as a subflow. So first of all, I'm going to create a screen component where I will be providing some choices. So its name is object choice. Now here I'm going to put a pick list. So its label will be select object. And here I'm going to put two choices. So first choice is contact label will be contact. And its data type is text and choice value is also contact. Then I'm going to create one more choice. So its API name is opportunity label will be opportunity. Then it's data type is text and its value will be opportunity. So this way you can see for this select object screen component I created two choices. Contact and opportunity and I'm clicking on done. Now I'm linking it with this. Now I'm going to put one more element that is for decision. So it's label will be check object. Now here I'm going to create first outcome. So it's label will be is contact. Then this select object pick list will be used here. And if it is equals to contact, then this will be first outcome detail. Now I'm creating second for opportunity. So again I'm using that pick list component available on screen. So this time it will be compared with opportunity. So now these are ready. I'm connecting this. Now I need to pull subflow element. So here I need to search for the sub for the flows. Those are individual flows. But here they will work as subflow. So it's label will be create a fortunately sorry create contact. And it requires an input. In this flow. I need to create a variable as record ID so that I can receive the record ID of the account. So I'm just creating it as a text type. It will be available for input and whatever input this flow will be receiving that will be passed to this subflow. So this way one subflow is created which is for contact. Now I'm going to create one more subflow. That is for creating opportunity. So it's label is create opportunity. It also requires record ID. So now I can use that created record ID variable. So we need to create it only once and then we can reuse it. So this way these two contact and opportunity flows are here used as subflows. Now I'm going to connect this decision. So if outcome is in this contact, this flow will work. If outcome is is opportunity, then this flow will work. So this way. Now these two flows are not used as independently as a separate flow. They are attached with this flow. So now I'm going to use this main flow on account record. And then we will create either contact or opportunity and choices will be there. And accordingly, subflow will be executed. So I'm clicking on save. So I am putting label as main flow, clicking on save, activating it. Now moving to account record page, clicking on edit page. So you can put this on a record page as well as you can put it on production. So from where you want to launch it that depends upon what you do. So you can use any source to launch the flow. So I'm using record page to launch this flow. So I'm placing it here. And here it is main flow. If I scroll it down, so here you can see pass record ID into this variable. This checkbox is available. So don't forget to check this checkbox because if you don't check this, the current record ID will not be available. So now I can save this page, click on back. So now you will see the main flow that is having two choices, contact or opportunity will be there. You can pick a particular choice and related record will be created automatically. So first I'm going to create contact. So here you can see three related contacts are already available. Now I'm going to create fourth one. So I'm clicking on contact and clicking on next. So here you can see contact flow automatically called which is asking for last name. So test sub flow. It is the last name of this contact and I'm clicking on next. So here left hand side you can see this test sub flow contact record is created. Now I'm going to create opportunity record. So if we see the opportunities, so here you can see two opportunities are already available. Now I'm going to create one more opportunity record. So its name is test sub flow opportunity. Stage is prospecting. Then I need to populate the date. So I populated this date and clicking on next. So you can see a flow executed completely and it is successful and here this opportunity is created. So this way friends, you can put your independent flows as a sub flow in Salesforce lightning flow. So I hope you understood how I demonstrated this and this is very much important because in many projects you will be requiring this like how we can put a particular flow as a sub flow in Salesforce lightning flow builder. So I hope this video will help you in your projects or assignments. If you want to watch more Salesforce training videos, you can search my name Sanjay Gupta on YouTube and you can watch various Salesforce related playlist and other programming related playlist on my YouTube channel. So do follow it. Thank you for watching this video.