 Hello everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate a scenario based on record trigger flow. Let's understand the requirement of record trigger flow now. So the requirement is like we need to copy files from one object to another. So the use case says like you need to copy files from opportunity to account when opportunity is closed one. So we have one account record, it can have one related opportunity, and that related opportunity will be having one or more than one files related. If opportunity is closed one, so you need to copy all those files which are related to opportunity to the account. So first we need to understand how files are managed in Salesforce. So basically whenever you attach any file on any object, so a content document object record is created for that file. So file always stores under this content document object. Then as object, let's say opportunity. So if you are uploading any file on opportunity, so file record will be created under content document object and opportunity object will be separate. Then the content document and that opportunity as object will be having a content document link junction record. So this content document link is junction object, which is related to content document as well as as object. So it means that file can be linked with more than one objects with the help of this content document link junction object. So now when I attach any file on opportunity, so file record will be created under content document because first time we are creating that and a content document link record will be created. But when the same file we need to link with any other object. So we just need to create content document link between the file existing file and the another S object. We don't need to create this content document record again and again, it is created once. So let me jump to. What so that we can create this so first of all, I'm jumping to opportunity and I'm going to pick an opportunity where account is related so I'm opening this which is having related account as well. And if I go to related list. So under this notes and attachment I can upload a file. So let's say I attach a file. So I just attached this file so what happened like one content document record is created and one content document link record is created. Now, if I close this opportunity like I change the stage of this opportunity has closed one. So this file should be available on account record as well. So we just need to create the content document link records between the content document record that is created for this file and the account object. Right, so I'm just going to add one more file here so that we can have multiple files those will be available on account so that we can have a loop and flow as well. So here we have these two files attached and once this opportunity is closed one we need to copy these these files to related account. So now I'm going to create the flow. So we need to create record trigger flow on opportunity and opportunity is updated, then we need to apply the condition. So here we have is one equals true. We can have one more condition like stays is changed. If you are changing the stays and is one is equals to true, then only we need to copy the files. So I'm clicking on done. So this way our condition is set now what we need to do. We need to fetch all the content document link records. So all the content document link records which are available for that opportunity we need to query and the same content document link records we will be creating for the related account. So first of all, from here I'm just going to have get records, so get contained document links opportunity. Here you can search for contained document link. Now we need to specify the condition so we need to fetch all those content document links which are related to the opportunity record which we just converted into closed one. So here you can search for linked entity ID equals record dot ID. If opportunity record ID is available in the content document links linked entity ID field, it means this content document link is related to this opportunity. So we need to fetch all those and then click on done. So now we have content document link reports. Now we need to apply a loop on this. So I'm just having a loop element loop over content document links. Okay, so this loop will be iterating now with the help of this loop one by one each content document link record will be available. So we need to create new content document links for account. So now we need to create two resources. Variable so contained document link, then type will be record. The object will be contained document link and then so this this content document link record variable CDL record variable will be storing one content document link information. Now, we need to create one more resource where we can store multiple content document links. So content document link list. To convert the variable into list you just need to enable this checkbox allow multiple values so it will become collection. Now here you need to create a assignment. So assign information to CDL record. So here you can search for content document link record, right and here you can see these information are available. We need to create content document link record for account. So first of all, we need to set content document ID, which is the file ID. That is already uploaded on opportunity that we will receive from current item of the loop that is contained document link record that is attached, or that is related to opportunity that is having a content document ID. So the same content document ID will go to this new record. Then again, you need to use content document link record dot. Now, this time you need to apply linked entity ID. So it will be the account record ID so you need to search for dollar record dot account ID. So the account record which is related to that opportunity on that account ID you need to store in this linked entity ID. Right now, apart from these two fields, you can fill values to other fields like CDL record dot share type. So here you can select viewer. And CDL record dot visibility. So here you can select all users right so this way one content document link record is created through this assignment, not in our we just created it in this flow only. Now, we need to add this content document link link record to the list. CDL record to list. So here I am having CDL list. Then add CDL record and done. So this way content document list is created. Now what we can do, we can just add sorry after completion of this loop we can just have a create record element. And just clicking on this plus sign which is after completion of loop. So here we need to select create record or create content document links on account multiple records those are available in a collection variable that is content document link list, and then done. So this way this flow is implemented. Now in the beginning I'm just adding one more condition. So we just need to check whether this opportunity is having a related account or not so if it is is not false. And only we need to copy the files. So if opportunities linked with any account then only we need to perform this operation so this is one more check. If it is not done. I'm clicking on save. So, copy files from opportunity to account. Clicking on save. Activate. So here you can see we have already these two upon these two files related to this opportunity. So I'm just doing a refresh. Now, if I open this related account in the new tab. Confirm, is there any related file or not so in the related list. You can see there is no file. Now I'm going to change the stage of this opportunity. So I'm just marking it as closed one. And clicking on save. So now I'm moving here and doing a refresh. So in the related list of notes and attachment you can see these two files are available. So this way through our flow automatically from this opportunity once it is converted into closed one stays all the files are related to account automatically. So this way with the help of this flow, I hope you understood how we can copy files from one object to another. So these two objects are important here one is content document and one is content document link. So if you copy the file so you just need to create content document link between the existing file and the new s object.