 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 screen flow. Let's understand the scenario which I'm going to demonstrate. So we need to remove duplicates from a collection variable in our flow. So sometimes when we create a flow, so we encounter a problem. We have a collection and in that collection, we have duplicate records. So we need to de-duplicate that collection. So let's understand how we can do that. So I'm creating a screen flow. So in this screen flow, I'm going to get account records. So let's see here we have account records. So I'm going to fetch the account records where name is starting with flow. And in one collection, I'm going to fetch accounts which have phone number as 123456. And then I will be merging both so that I will be having duplicate records in a single collection. So here you can see this record starts with name flow and it is having this phone number as well. So these two records will be available as duplicate. So twice they will be available in the collection. So we need to do duplicate them. So here I'm going to use get record. So first I'm going to get accounts with accounts by name. So wherever name starts with flow. So those records will be varied. You need to select all reports done. Then one more time I'm going to use get records. So this time I'm going to get accounts by phone. So here you need to search for phone equals 123456. So wherever on account report, phone is equals to this value. So those accounts will be queried. And again, you need to select all accounts. Now I'm going to add these both into a collection variable. So I'm going to create one more variable naming it as accounts. Record and object as account allow multiple values. Now I'm going to use assignment. So I'm going to use this collection and I'm going to add all the records which I got through name. And again, I'm selecting accounts, add, then get accounts by phone. So the records which we receive through name and the records which we receive through phone, both are added into this accounts. So I clicked on done. Now I'm going to add a screen so that I can show you whether this collection accounts is having duplicate records or not. So it will be displaying account ID. So I'm using display text. So I'm searching for accounts done. So now I'm going to save the duplicate collection. So now I'm going to debug. So on screen you will see total six IDs and you will see the duplicates as well. So here you can see I'm selecting this ID. So I'm going to select this and here. So you can see this ID is available here as well. It is available twice. Then if I select second one, so you can see it is also available twice. If I select this ID, so it is available single time. If I select this ID, it is also available single time. So it means the initial beginning ID is available here. The beginning ID, this ID is available here and this ID is also available here. So I displayed accounts. I displayed this account on the screen. So here you can see one ID is available twice. So we need to deduplicate it. Now let's learn how we can deduplicate that account's collection variable. So if you want to do duplicate that, so first of all what we are going to do, we are going to have one more resource as collection sort. So I'm labeling it as a sorted accounts and here I'm going to select this accounts which we need to sort and we are going to sort it basis on the ID and in ascending order. How many items to keep after sorting? So we need to keep all the items. So in this sorted collection, those account IDs will be sorted. So I clicked on done. Now we need to start a loop. So I selected loop. So loop over accounts and here I'm going to select the collection variable. So here I'm selecting this accounts and direction will be first item to the last item. So I clicked on done. So this way this loop will iterate. Now I am going to create one resource as a variable. So this resource I'm labeling it as previous user ID. So it's data type is text and I clicked on done. Right. So what we need to do, we need to now apply a decision. So like when this loop will be trading, so this loop will give us IDs one by one. Those are available in the collection and we need to check that previous user ID with that loop current value. So if both are matching, then we need to skip and if they are not matching, then we need to add that ID into a new collection. So I'm going to create one collection as well naming it as final list or we can say final accounts. So record account, allow multiple values and done. Right. So here I'm going to apply a decision. Check previous ID. So here I am writing yes. So if previous user ID is equals to so loop over accounts, so we will be selecting the ID. So current item from loop and that's that current items ID. If it is equals to previous user ID, it means that record is already added into the final list. And next we need to have no. So previous user IDs does not equal this loop over accounts.id. If it is not equal, then we need to add that account into the final list. Okay. So here you can see we have these directions. So here if this previous ID is not equals to the ID which we received from the loop, so in that case we need to assign. So here I need to use final accounts, then add and current item over loop. So that item will be added into this final accounts. Right. So here you can see if that ID is matching. So we will go to yes and then move to loop again. Otherwise, if it is not matching, so that ID or that account record will be added to the final list. Now after this, like if it is matching or not matching, we need to assign the current account record that we received from the loop that ID into the, this previous ID variable. So here I'm going to add one more element that is assignment. So it will be the current ID. So in the previous user ID, we need to assign current item from loop. So the current item, which we are processing through the loop that current items ID, we need to assign in the previous user ID. So next time this previous user ID will be matched here in the decision. Right. So this way, this loop part is implemented. So I'm just showing it on the same page. Right. So what we can do now after this, like once this loop will be completed and after last item, if you want to display the values. So here we can write display text. So here I need to select final list. So final accounts. Okay. So I'm just clicking on save, clicking on Bieber. So as I click on run, you will see six IDs here. Now if I click on next, so you can see only four IDs. Those are unique. So if I go and compare them. So here I have this ID. So this was the, okay, this is through the loop. So we need to go above. Yeah. So this is the screen result that we received through first screen that is available in the flow. So in flow, we have two screens. So through this screen, we are getting the all data that is having duplicates. And through this last screen, we are having the unique data. So if I go here and if I compare, so if I select this, so you can see it is available here once and here it was available twice. Then here also, if I copy this, so here it is available twice. And on the screen result, it is available once. So this way you can see like duplicate records are removed and the deduplicated like unique records are available in the final accounts. Okay. So this way, with the help of this demonstration, I hope you understood like how we can deduplicate records. Those are available in the single collection variable. So we deduplicated a single collection variable. If you want to deduplicate two collection variables and then you want to merge them. So for that, you can watch upcoming lesson or video.