 Hello, everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. Let's understand the requirement that I'm going to demonstrate in this video. So we will be integrating our flow with code. So the requirement is we need to call apex invocable method through record triggered flow. So in my previous video, I demonstrated you how we can call apex invocable method through screen flow. So here you will see that similar implementation with the help of record triggered flow. So the requirement is we need to call apex class. We will be passing account ID into the class through flow and we will be fetching some data from apex into flow. So let's jump into the org and here I'm going to first open the developer console. So you can just click on this gear icon, which is available at top right corner. And we need to open developer console where you can implement your apex code. So I'm creating new class action on account. So inside this class, I'm going to implement the invocable method. So whenever you want to implement any invocable method. So first of all, you need to implement invocable method annotation. So you can write it like at the rate invocable method, then you can define your method. So public static, then return type will be list of string. Name of method is return account name. And this method will be receiving list of ID and that list of ID will be stored in this IDs variable. Now inside this method, we can write the code. So I created a list of string where all the account names will be stored. So what will happen, whatever account record ID we will be passing through flow into this invocable method. So that account name will be returned through this list of string. So here I'm going to create list of account. So here I applied an SOQL. So which will be querying account names from account object where ID is available in this IDs list. So the returned result will be available into accounts. Then I'm applying a follow. Now what you can do instead of writing this separately, you can just write this SOQL here as well. So you can implement it here as well and just remove this statement. So what will happen if data is not available? So null check will be applied automatically here with the loop. Now inside this loop, you can write account names dot add account dot name. So whatever account records will be queried, their account names will be added into list of string named as account names. So this list of string will be storing all the account names. Now after completion of this loop, you can write return account names. So this list of string will be returned to the flow and in flow, you can process it. So I'm just saving this code and jumping to create a flow. So I just clicked on new flow. Here I'm selecting new record triggered flow. So I'm selecting account whenever account is created. Then if you want to apply any condition you can and then I'm selecting actions and related records and clicking on done. Right now here I need to click on plus sign where I can find this action. So you need to click on this filter by and just select the type and click on apex action. Now here you will find whatever invocable apex methods you have defined. So right now we implemented action on account. So I'm selecting it. I'm providing a label as call apex and here we need to set the input values. So just enable this and here you can pass the account ID through which this record trigger flow will be triggered. So as you know, if you have like implemented record trigger flow earlier. So whenever record trigger flow initiates its execution through particular records so that records ID will be stored or other field information will be stored in the global variable. So here I can search for dollar record. So dollar record is a global variable which stores all the field information of the record through which this record trigger flow will be triggered. Right. So here you can select it then select the ID so that this records ID will be passed. Now here you can receive the returned value which will be returned from here. Right. So you can set the output values here you need to create new resource where your returned value will be stored. So I'm creating a variable named as account names API name is account names and it will be off type text. Allow multiple values and available for output. So it will be receiving output from outside. Right. So I'm just clicking on done. Creating it again. I guess yes now it is available. So just to correct why creation of this output variable I initially created it as collection variable. So collection is not allowed when I created collection variables. It was not selected here and it was not available to select. So you just need to create a single variable right that will be storing that value which will be returned from here. So though we are returning string but still this variable will be able to store that value. So I'm just clicking on done and clicking on save. So call apex through record record flow and I clicked on save. Right now if you want to test this flow. So what you need to do you need to debug it so that you can see the step by step execution. Whether this account name variable is receiving some value or not. If it is receiving some value then if you want to use it in further calculation. So here you can add more elements and you can perform certain operations. Right. So I'm just clicking on debug. Now it is asking to search for accounts. So I'm selecting this account record. So here for the debug run we trigger the flow as if this record is created, updated or deleted. So it will consider like I'm just creating this record. So I'm just clicking on run. So here you can see a flow executed now step by step. I can expand these all. And here you can see this ID is passed into apex and apex returned this value into this ACC name variable. So this way apex method is called and the value is returned here. Now what we can do if you want to use this like if you want to put this value onto that account record. So I'm just going to show you like how you can do some calculations. So update record or update account record and what I will be doing I will be updating that account record description. So account description will be having this ACC name. Right. So account name we are fetching through apex and that we are storing into the description. Right. So I'm just clicking on done. Now save. Activate. This time I'm going to create new record and you will see in the description that account name will be populated. So account report triggered flow and I'm just clicking on save. So new account record is created. If I go to details in the description, you can see account name is populated account RTF. Right. So this is through this apex that we call. So this is just an demonstration to show you like how we can pass. IDs of the current record through which record trigger flow is initiated into apex and how from apex we can receive the data and we can use it for further process. So if you want to do some calculations here and then you want to return some value to flow back so that you can done. So this way I demonstrated you how we can call apex invocable methods through record triggered flow.