 Hello, I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So let's understand the requirement now related to record trigger flow scenario. So I'm going to demonstrate the record is created, record is updated and record is deleted criteria. Those are available when you implement record trigger flow. So I'm going to demonstrate the requirement which is available in front of you. So we need to count total contact records related to an account when, so first is a contact is created. So if you're creating a contact, so on account there should be a field where in that field one will be increased as we are creating a new contact related to that account. So one by one, I will be demonstrating all these use cases. So let me create a record trigger flow and I have already created a field. So here you can see I am under object manager under account object and here you can see I have already created a total context field which is of type number. And if you go to a count record page, if you go to details, so here you will find that total context, right? So now I'm going to implement the flow for you. So I'm selecting object as contact, then trigger the flow when a record is created. Then here we need to apply the condition. So if we are creating a contact, so we need to make sure it is linked with an account. So if account ID is null, false, right? So if account ID is not null, it means that contact that you are creating is connected to a particular account. And this record trigger flow I am creating for contact object, but it will be updating the value of account. So that's why I'm selecting actions and related records. Clicked on done. So now here I'm going to implement this element. So what I need to do, I need to query all the existing related contacts with the account for which we are creating new contact. So for example, if I open any account record where already some contacts are available, so let's say if I open this account, this contact, sorry, if I open this account and here you can see one contact is already available. Now I'm creating one more contact related to this account. So what I need to do, I need to query all those related contacts. So for that purpose, I'm using this get records element. So here I'm writing get contacts. Now here we need to provide the condition. So I need to query all those contacts which are related to particular account and which account with which the newly created contact is connected. So here I need to write account ID equals then the newly created contact record information will be available in this dollar record variable. And through this, I can fetch the related account ID. So the newly created contacts account ID, if it is equals to other contacts account ID, it means all those contacts are connected to a same account. So those will be varied. Here you need to select all records and automatically store all the fields and then click on done, right? So this way this get contacts will be having all the available contacts related to that particular account. Now we can assign the count of this collection. So basically get contact will create a collection automatically. So this collection size we need to store in a variable. So here I'm going to create a variable naming it as contact count. Its data type will be number and its default value is zero and done. Now I'm going to use an assignment. So here contact count equals count and then you need to select get contacts. So whatever records are available in this get contacts they will be counted and value will be available in this variable. Now I'm clicking on done. Now we need to update the related account. So we need to use update records. So we need to update the account. Then we need to specify the condition. Now here you can select ID equals then the current contact record dot account ID because contact is connected with account and that account we need to update and which field we need to update total contacts equals to contact count, right? So this way this flow is created. Now I'm going to click on save. So I'm just clicking on save. Now I'm activating this. So here you can see right now this field is blank, right? Now I'm going to create new contact under this account. So I'm clicking on new. So I'm creating new contact and clicking on save. So here you can see total two contacts are available if I go to details. So here you can see total two values available. If I go to related and create one more. So now total three contacts are available if I go to details. So you can see total contactors three. So this way our first case is working fine. Now I'm going to use the update. So in case of update we have two scenarios. First is contact is updated to be linked with an account. So right now what is happening? Contact is available, but it is not connected with any account. Its account ID lookup is blank. So if we fill that, it means now we are connecting that contact with an account. So in that case that account will be having the updated count. And later on I will be explaining like how we are linking contact with any other account. If it is already connected with an account, we are going to link it with another account. So one will be having one decreased count and one will be having increased count. So right now I'm showing you if contact is updated to be linked with an account. So I need to modify the flow. So this time I'm going to select this option. So like if record is created or updated, right? And if we select this record is created or updated or simply updated. So we have these two options. These two options are not available in case of create. So I'm selecting this only when a record is updated to meet the condition requirements. So if it is updated to have this account ID, so earlier account ID is null and now it is having some value, okay? So I'm just clicking on done. So now again, we need to get the contacts. Those are available in this report which we updated. So the current report which we updated contact, it will be having account ID. So basis on that we will be fetching all the contacts which are related to particular account. And then through this assignment we are counting the value and we are updating the related account. So I'm just saving it and activating it. So now if I go to this account, so here you can see right now three contacts are available and count is three. Now I'm moving to contacts and I'm going to see this contact is not connected with any account. Here you can see lookup is blank. So I'm going to select that account and I'm going to click on save. So if I go to this account and go to details, so here you can see total count is four. If I go to relatedness, so here four contacts are available. So this way on update also the same flow is working fine. Now what we need to do, we need to implement the scenario. Like if contact is updated to be linked with another account. So in this case, what will happen? Like the contact which is connected with this account, I'm going to connect it with another account. So this account will be having value as three and the new account with which I'm going to connect this contact will be having one value increased. So if we read this, like when to run the flow for update record. So it says, perhaps you want the flow to run only when the triggering record has changed from not meeting the requirement, condition requirement is meeting the condition requirements when that's the case choose the second option, right? So if it is not null, then we are filling some value in that case it will run. But in our case now contact is already having some account in this account ID and now we are changing it, right? So this time I'm selecting this option. Every time a record is updated and meets the condition requirement. Like if account is not null, then it will be executing. So I clicked on done. Now in this case, I need to update two accounts. One that we are populating as a new account with which your contact will be linked and we need to decrease the account which was earlier parent for that contact, right? So here we use this record and then through this record dot account ID we query the context and then we counted and updated the account. Now I need to have some more things. So here I'm using get record. So again, I'm getting get context for existing account. Account ID equals now here we have one more variable, global variable that is record prior. So for example, if I go here, open any contact and if I try to change this, so right now it is having Burlington Textile. If I change it and select any other account. So it means this will go to dollar record and the earlier one Burlington Textile will go to record prior, right? So previous value will be available with record prior and this new value will be available with dollar record. Okay, so this record prior dot account ID right? So this way the existing account which was linked with the contact that you are updating the context which are related to that account they will be queried and after this we can use the assignment variable. So here we need to create one more variable. It should be of type number, zero default value, zero and then done. Now, if it is equals to, okay, so equals count and then get context for existing account. This way it will be counted and now I need to update the account. So I am just selecting update record. So we can say like update existing account then specify the condition. So we need to select the account then here ID equals then record prior dot account ID and then total count equals to count contact for existing account. This will be stored and then I am clicking on done. So this way these two things we need to do because we are updating the contact which is already connected with an account. Now we are going to connect with that contact with new account. So both the account should be updated. So I am clicking on save as activate. So now I am going to connect this contact with new account. So let me just show you the account which I am going to select as a new. So if I go here, so here one contact is available and total count is zero. So now if I update this contact which is connected this Burlington textile. So Burlington textile is already having four accounts related. Now I am changing it and linking this contact to this one. So this ACC one one zero two is already having one contact. Now it will be having two contacts. So on ACC one one zero two total count will be two and on Burlington textile it will be three. So if I go to ACC one one zero two. So here you can see total count is two. Two contacts are available if I go to Burlington textile. So here you can see three records are available and total count is three. So this way the third use case is also working properly. So I hope with this way you understood the difference between these options like when to use account sorry a record is created and when to use created or updated both. Now the time is to use a record is deleted. So if contact is deleted then also total contact count should be updated. Right so in that case you just need to use the delete and if it is not null and then done. Now I am just going to remove these things because these are not required now. And maybe if you want to implement all these things together so you can have three different flows. One is for create or maybe for create update one flow and for delete another flow. So that you don't need to remove those elements. So again we need to get the records. So this will be same the deleted record information will be available in this dollar record variable. So this way we are fetching all the contacts related to the account through which that contact was related which we are deleting. And we are assigning the total count in similar way and we are updating the related contact. Right so this way if I save it create a new version activate. So you can see contact is deleted if I go to details. How you might be thinking like why this record total count is not changed. So there is a catch that you need to understand. So actually this is a limitation in the flow. So I tried to create a delete operation. So here you can see it is optimized for before the record is deleted. Right so here you can see like it is optimized for before the record is deleted. It means if you implement the flow and select this record is deleted. So it means you can do operations on the deleted record only. If you want to do some operation on the related record though those are related to that deleted record then your operations won't be performed. Right so that's why it is not working properly in case of deleted. So this is a limitation and maybe later on like till this May 2022 this delete option is having before the record is deleted. Maybe in upcoming releases you will see after the record is deleted feature. So in that case this requirement will work properly. Right so this way I showed you the differences between record is created versus updated versus deleted. So in case of created and updated you can do operations on the same record through which record trigger flow is triggered as well as on the records which are related to that record. But in case of deletion you can do the operation on the record through which your record trigger flow is triggered only. If any record is related related to that record then it won't work. Right so this way I hope you understood the differences between record is created versus updated versus deleted.