 Hello, friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to demonstrate you how you can apply validation rule based on values of existing records. So if you are trying to create new record or if you are trying to update any existing record and you want to apply duplicate check with the help of validation rule so that work around I am going to demo in this video. So we can apply duplicate rules as well in Salesforce, but those are limited to certain objects. So this work around will help you to implement duplicate check with the help of validation rule and record trigger flow. So it will be executing on before insert and before update. So we need all these three things checkbox field validation rule and record trigger flow to accomplish this requirement. And before starting demonstration. If you want to watch more Salesforce training videos so you can go to description of this video and you will find links of all Salesforce playlist there. So now I'm going to start my demonstration so I'm going to implement this on a custom object that is employed and I will be checking the designation field so I will try to fire that validation rule when duplicate designations are sorry duplicate records based on designation are created. Right, so first of all, let me search employee object. So I already created a field that is validation check so you can create this checkbox field so initially it will be false and don't put this checkbox field on the page layout because this will be used in validation rule only. So we don't require this on page layout after creating this field, you need to create a validation rule. So I created validation rule as a check existing record. So what you need to do you need to just put that checkbox field in the condition formula. So if it is false, then this validation rule will not fire. And if it is true then validation rule will be fired. And rule name active true this checkbox field will be available here and in error message you can put the message as per your requirement so I put you cannot create or update the code with same designation, right. So, error location will be top of the page you can choose any option as per the requirement. Now I'm clicking on save. So these two requirements are fulfilled now if a user tries to create or update record with same designation that is already available. Then we need to run this validation rule. So we need to check this checkbox field as true. So for that purpose I'm going to create a new flow. So flow will be record triggered flow. So this option you need to select record trigger flow. And from here you can select this option or record is created or updated and run the flow on before the record is saved, right. So from here we need to choose the object. So I'm choosing employee as the object clicking on done. Now I'm putting get record. So now I need to get existing employees based on a particular field. So what I'm trying to do whenever a record is created, whenever an employee record is created or updated. So this flow will be triggered and newly created or updated record information will be available in this flow. I'm just checking all existing employee record based on this designation, whether a particular designation that we are trying to create or update is available or not. So one thing you need to notice whenever you create a record or update a record so that record information will be available in this record variable. So here you can put record or designation and here we are trying to fetch existing records based on this condition. So if new record designation matches with any existing record. So those records will be stored in this API that is existing employee. So this unit to choose these settings and click on done. You can connect it. Now you need to choose a designation. So validate existing records present so if existing records are present so this get existing employee is null will be false. So if this resource is containing one or more than one record so it will not be null. It means with a designation that you are trying to create is already available. So I'm clicking on done. So if this condition is true then I need to enable that checkbox has true so enable validation checkbox. So that we need to enable on the current record that we are trying to create so record dot validation check equals true. So if records are already available with same designation then this condition will be true and checkbox will be enabled. So this way I created this record trigger flow. So now you can save this. So fires when fires on employee so label you can decide as your own as per the requirement I'm clicking on save and activating this. So now it is activated moving here. So I need to create new employees. So here you can see let's say I'm opening this existing record and here sales manager is available as designation right. So what I'm trying to do. I'm going to create new employee record with same designation employee idea and putting value random value and I'm clicking on same. So here you can see you cannot create update record with same designation. Now if I put sales manager one so this record will be created. So this way with the help of record record trigger flow we created this validation check. Now if I try to update this existing record and click on save so again you can see that validation rule is firing. So this way you can use this work around whenever you want to check values of existing record while trying to create new record or updating a particular record. And based on your criteria you can enable a particular checkbox that will be used in the validation rule. So I hope this work around may be useful in your projects so if this helps you so I will be grateful. So I hope you understood whatever I demonstrated in this video. If you want to watch similar kind of videos or videos related to Salesforce so you can go to description of this video and you will find links of various playlist available there. Thank you for watching this video.