 Hello everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate a scenario related to screen flow. Let's understand the scenario which I'm going to demonstrate. So I will be explaining how you can remove duplicates from collection variables in a flow. So let's first understand like what records I will be using. So I will be querying account records through name and through phone number. So here you can see we have this account which is starting from flow. This account which is also having name as flow account one then flow account two. I will be querying these three account records through name and through phone number I will be querying this one which is having one, two, three, four, five, six and this and this. So these two records will be query twice one through name and one through phone. So we need to do duplicate those two collection variables, and we need to merge them and we need to remove duplicates. So now jumping here and going to create new screen flow. So first of all, I'm going to use get record element. So here I'm going to fetch the accounts based on name. So the object I'm selecting as account and here I need to provide the conditions or name starts with flow. All the records and automatically store all the fields. Right. So if you select this all records. So this account based on name this this variable will automatically convert into collection variable. Now I'm done. Now I'm going to use a screen so that I can show you the records account very based on name. So those I'm going to display. So here I'm going to use display text. So I'm clicking on done then again I'm going to use get record element. So to query the account records based on phone. So I'm going to search for account phone equals 123456. Again I'm selecting all records. So this get record variable will also be converted into collection variable. It will store multiple account records. So here I'm going to display account which we queried based on phone. So here account based on phone. So those records which are queried basis on phone they will be displayed here. So I'm clicking on done. So right now I'm going to save this flow. So I'm saving it and I'm going to click on debug so that we can see the results. So you will see only two screens. So here you can see three records are available. So here we have ID so let me just go and modify it. So here if we go so here you can see first screen is showing three records with ID. So I'm just clicking on next so that you can see the next screen. So now here we can see the result of screen one. And here you can see the result of screen two. So I'm just copying this ID and searching it here. So you can see this is matching this this account ID is for same record. So this account is queried through first get element and it is also queried through second get record element I'm copying this as well and searching so you can see it is also common. Now if I copy the third one. So it is not available. It means this first ID. And this this this one which is available here. These are unique and these two these two IDs. These two which I selected here they are available here as well. It means two records are queried, which are duplicate in first get record element as well as in second. So now we are going to deduplicate them. So first of all, if if I want to start the duplication. So I need to create one variable that I will be using for deduplication. So I'm going to create new resource as a variable. And I'm naming it as merge records, it will be of type record. The object will be account because we queried account records and here we need to use allow multiple values. Now I'm clicking on done. Now I need to use one assignment variable. Right. So in this assignment variable, I'm going to apply the logic. So, so deduplicate and merge records. Now here I'm going to build the logic through which we will be removing the duplicates. And then to do first I'm going to select this merge records collection. So it is also a collection variable. So at left hand side you can see we have three record collection variables to which we created using get record element and one which we created as resource merge records. So first of all, I'm going to assign accounts, those are query basis on name as is into merge record. So whatever data is available in this collection, it will go to this collection. Now I added one more row. So here again I'm using merge records. This time I'm going to select remove uncommon account based on phone. So the records which are uncommon between merge records and this account based on phone, those will be removed from this merge record. Right. So only common records will be available here. Now you can select account based on name here and you can add what are available in this variable account based on phone. So both will be must like three records are available in this collection variable account based on name and three variables are available in this variable which is account based on phone. So now this account based on name will be having six records. So what we need to do again, we need to search for account based on name and we need to select remove all and here I'm selecting merge records. So this merge record will be having the duplicate. Right. So all the duplicates are removed. So now account based on name, then add and merge records. Right. So this at line number three row number three. We were adding account based on phone into account based on name like so this collection will be having six records. So we are removing all the duplicates. Right. So all duplicates are total for four records will be removed from here from name and then this merge record will be having two records because we just retained only common records so common records are two. So those are available in merge records so they are added back into account based on name. So finally account based on name will be having four records. Unique. Right. So you can you can do one more thing like you can create one more variable and account based on name collection variable you can assign into that as well if you want to like store the unique like and deduplicated values into separate collection variable. So now what I can do I can create one more screen naming it as the duplicate records and here I'm right selecting display text. So display records and here I'm selecting account based on name and clicking on done. So I'm just clicking on save and clicking on debug. So now we need to carefully see the results. So screen one will be showing three records. So I'm just moving next so that I can have the results here. So through screen like accounts, query based on name. They are available here. Again, I'm moving to next. So here you can see these are the records which we query through name. These are these are the records which we query through phone. Right. So here, these these two records, these two record IDs are available here as well. Right. So if you compare so they are available here. So now if you go further so this way that assignment walked and this is the result right now. What we can do we can see like if I if I selected and search. So you can see it is available here. It is available here so it carried through name it carried through phone and here it is available only once. So earlier it was available in first collection as well as in second collection but in third collection like like finally after assignment operation. We have all the records after removing duplicates. All the records are available in the collection variable which is account based on name. So here you can see this ID is available once. Now if I select this ID. So this ID is also available in first collection second collection but after assignment it is available once here. Now if I copy this so you can see this ID is available only once here and here also it is available once and if I select this one. So it is also not available in this collection it is available here only and here only right so this way we remove the duplicates and account based on name collection is having the unique values. So you can do analysis of this as well so that you will be able to understand so these are the results which are available on account based on name. So this merge record is having only two accounts and account based on name is having four account records and these were the duplicates which are removed from that collection. So this way with the help of this assignment like you can remove duplicates from two collection variables.