 Hello everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate a scenario based on auto-launched flow. Let's understand the requirement that I'm going to build with the help of auto-launched flow. So I will be calling the auto-launched flow through APIX code. So in flow, we will be receiving ID of opportunity record as input. So I will be calling the auto-launched flow in the APIX code. So APIX will be passing that ID of opportunity record. So we will be receiving the input value in the flow and then inside flow, I will be fetching the opportunity record and will be returning the stage name back to the APIX class. So this is the requirement that I'm going to demonstrate. So to accomplish this requirement, I will be implementing auto-launched flow along with, will be writing some APIX code. So jumping to the org. So first of all, I'm going to create a auto-launched flow. So here you can see descriptions is like launches when invoked by APIX. Then processes. So processes I already demonstrated in my previous video, like how we can call auto-launched flow through record-regard flow. So in this video, I will be calling this auto-launched flow through APIX. So I'm just clicking on create. So here I'm going to create two new resources. So first variable I'm naming it as record ID. It will be of type text and will be available for input. So this variable will be receiving input from the APIX code. That's why I'm enabling this checkbox. I clicked on done. Now I'm creating one more resources variable and here I'm going to store the stage name. It will also be of type text and it will be available for output. It means this variable will throw its value back to the APIX code. So I clicked on done. So these two variables are available here. Now I'm going to use get records element so that I can get opportunity record. So here I need to select the object as opportunity. And here field will be opportunity ID equals record ID. So this is the variable that will be receiving the value from the APIX code. So we need to store only the first record. And I need to store the stage field value into the stage name variable that I created. So I'm choosing third option, choose fields and assign variable. And here we have two options where to store field values. So I have already created a separate value. Sorry, I have created a separate variable. So I'm going to use that. So on left hand side, I'm choosing the stage name. And on right hand side, I'm choosing the stage name. So left is the field that is available on the object. And on right hand side, we have a variable that we created in the flow. So the opportunity record, which will be queried, its stage field value will be assigned into this stage name variable. So I'm just clicking on done. Okay, it is showing one error. Okay. So what I did, I just choose this sort order as well. I sorted based on ID. And now I'm clicking on done. So it is implemented. Now I'm going to save it. So this flow is going to be saved. Now I'm going to activate it. Right. So this flow is activated. Now I need to open the developer console. So if you want to write apex code. So just click on this gear icon and click on developer console. So developer console will be open in the new tab where you can write the apex code. So I'm just writing the apex code in this execute anonymous window. So it is available under the debug menu. So click on open execute anonymous window. Now here I'm going to implement the code. Right. So I'm creating a map of string comma object type and I'm naming it as parents. And I'm going to initialize it. Now inside this map. I'm going to put two things. One is record ID. So record ID will be the key that is string. Right. And here I need to pass the ID of particular opportunity record. So I'm moving here. And I'm going to open this opportunity where the stage is prospecting. So if I open this opportunity. So in the URL you can see here we have the ID. So you can just copy it. And here in the single quotes, you can paste it. Right. So this way in this map. Key is record ID. And its value is the ID of opportunity record. Now in the next line, you need to write flow dot. Interview dot. And then you need to use the API name of the flow. So our flow is already saved. So this is the flow. And if I click on save us. So from here I can find the API name. So I'm just copying this API name. And I'm going to use it here. Then batch opportunity stays. So this is the variable. Right. So this will become a type. And we are creating a variable of this type. Then after equals to new. So I'm putting it in new line. And the same. Type I need to paste here. And then I'm passing parents. So this way the auto launch flow that I created will be receiving this parents as a parameter. So that parameter will be available here. Like it is already created here. So it is having key as record ID and value as this opportunity ID. Now. We need to use this variable fetch opportunity stays dot. Start. And after this. Ring dot. Return value equals to. Then I'm typecasting. Returned value in string. And fetch OPP dot. Sorry. Fetch OPP stays dot. Get variable value and variable name is. Stays name in the flow. So I need to use that here. So this way flow will be called and it's returned variable, like wherever the variable is having this available for input checkbox check. So those variable you can fetch like this. Its value will be available in this returned value. It will be typecasted into string. And now we can use system dot debug. So if you want to show some result in the apex. So you need to use system dot debug. So here I'm using flow returned. And then return value. So this way with the help of this apex code, I called the auto launch flow. Now what you need to do, you need to run this code. So. Just check this checkbox so that locks will be opened because the output of this statement will be available in the locks. So I'm just clicking on execute. Now here you will see the locks. So locks are open. Because we checked that checkbox. If you just forget to check the checkbox. So at the bottom you can see locks are available. So you can just double click on those locks and you will see the similar results. So it is just loading. So locks are generated now here step by step. You can see how this is executed. So first we execute anonymous apex. Then it is calling this flow. Then if you scroll down. So here you can see this map is initiated. Then flow interview started. Then. Or this call auto launched flow through apex flow. Executed then get variable value. And here you can see this is the return value which is prospecting. So it will be available in the debug. So if I open this so you can see line number nine is having the system dot debug. And this is like in square bracket. It is showing line number. So debug is showing flow return prospecting. And if I go here in the details. So on this record, you can see the stage value is prospecting. So this way with the help of this demonstration, I hope you understood how we can fetch the value that is available. In the flow. In apex. Right. So. This we passed as an input params and through this get variable value. We receive the flow value as an output in the apex. Right. So this way with a simple demonstration, I hope you understood how we can call auto launch flow through apex and how to pass input from apex to flow and how to send value as an output from flow to apex. So both the things I demonstrated.