 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 make a field required. So there are four different ways through which we can make a field required. So while creating a field, there's a checkbox available. So if you check that checkbox is true, so we can make a field required on that level. Then we have page layout, validation rule and trigger. So I will be demonstrating you these four options one by one so that you can understand them practically. Before starting, if you want to watch more Salesforce training videos, you can go to description of this video and you can find links of various playlists there. So now starting my demonstration, so I'm opening account object. So I'm going to edit a particular field. So I'm not going to create new field. I'm choosing existing one. So this is the field whose label is active and I'm clicking on edit. So this is a pick list field. So here you can see this required checkbox is available. So always require a value in this field in order to save a record. So if we check this checkbox, then whatever record you will create for this account object on each record, you need to populate value for this field. So I'm checking it as true, clicking on save. So now whenever I create or update any account record, so this active field must be having a particular value. So I'm going to open any account. So I'm just opening existing account and on this account, you can see yes, here active is populated. So I'm going to edit clicking on none and clicking on save. So here you can see the following fields active. So here we need to populate some value and then we can save this record, right? Now if I try to create new record. So account name I'm providing and this active and living as it is. I'm not providing any value to it and clicking on save. So here you can see the view, the following error on this page. So here you can see required fields are missing. So we need to populate this. So I'm clicking on no. So now this record is created. So this way on field level, you can check this checkbox so that whenever you are creating or updating any record, so you need to populate that field, right? So this is the first way to make a field required. Now I'm clicking on edit. So drawback of this required is you don't have any option like, let's say you have two record types and for one record type, you are using one page layout for another. You are using another page layout and for one page layout, you want this to be required and for another, you don't want. So if you check this checkbox, then that functionality can't be implemented. So I'm unchecking this, clicking on save. So to implement a field required based on the particular page layout or record type. So that you can do on page layout itself. So let's say we have four different page layout and on this page layout, I just want to make this field as required. So I need to open this and I need to search for that field. So here it is active. So you need to click on this properties and here you can see this required option is available. So I can check this checkbox from here, clicking on OK and clicking on save. So this way I'm making this field as required on a page layout level. So if I try to create new record now, so I'm putting account name as test and I'm leaving this active as it is. So here you can see this red mark is available now. And if I try to save, so here you can see these required fields must be completed and field name is active. So we need to populate this and then only we can save this record. So now this error was thrown because we applied required on page layout level. So if you have multiple page layouts and on some page layout, you want to make a particular field required and on some layout you don't want. So you can do that from here. So I'm unchecking this. So this was our second method that is to make a field required on page layout. So I'm clicking on save. Now if we make a field required on page layout, then it will be required for all the profile users for that specific page layout or record type. Now if you want, like some profile users must be entering that value and some profile users can skip that value. And let's say if you are creating your record, then you can ignore the value and if you are updating the record, then you need to provide the value. So these things you can control with the help of validation rule. So now I'm going to create a validation rule on account. So creating new validation rule, check active. Here you can write the description and here you can create your error condition formula. So the method we need to use is blank. Field is active. Right. So if active is blank, then this validation rule will be fired and the error nurses please populate value. And here we have two options like error where we want to display on top of the page on field location. So I'm selecting field and clicking on save. So right now this validation rule will fire. There's some error. Okay. It is a pick list. So I need to use any other method here. So let me modify this one. Let's check the syntax. Yeah, it is correct. So I'm saving this. So whenever you apply is blank on pick list, so you need to use text method as well. Right. So that we can pass the text of pick list and then we can check if it is blank or not. So let me try this now. Let's see whether it executes or not. Yeah. Actually. So I just refresh this page and now I'm going to create new account and clicking on save. So here you can see review the errors on this page and error will be available with the field. Please populate value. Right. So validation rule is working as well. So now I'm going to edit that validation rule and I will modify like if you are creating your record then this validation rule will fire otherwise not. So I'm putting is new and is blank. So if new record is created and then this active is blank then validation rule will fire. So if you're modifying or updating your record and then in that case if active field is blank then this validation rule will not fire. So this way you can add additional functionality while using validation rule for making a field required. So now if I try to create new record and click on test. You can see this error is still available. But if I try to modify any existing record and if I leave active field as blank then it will be saved. So you can see no error is coming because in validation rule I applied is new. So if record is new then only this validation rule will fire. So similarly you can apply record type checks. You can apply profile checks. You can apply permission set checks in this validation rule. So this way you can this way you can customize your validation rule so that you can make a particular field required. So this was third thing a validation rule to make a field required. So now last one is trigger. For trigger we need to use custom code so that we can make a field required. So I'm unchecking this and I'm taking you to the trigger. So this trigger I have already created. So it was commented because I just demoed you three other ways. So now I'm making it as uncommented. So this is the trigger name will be working on account before insert before updates. So here also you can control like when this trigger will be executing then the new record information will be available into trigger.new. So we are checking a ACC dot active is blank or null. Then this error will be added right. So in this code you can control various things as well like you can control record type profiles. Other checks you can apply. So now I'm going to refresh this and if I try to create new record. So I'm putting test here and clicking on save. So here you can see account. Sorry account rating here mentioned we are checking for active. So we can modify this active is required. So I'm modifying this message so that appropriate message should be displayed. So again I'm clicking on save so you can see modified error message available here active field is required. Right. And if I modify any existing account and if I leave active as blank. So in that case also this error will be displayed. So I'm clicking on save. So here you can see active field is required. So this way I demoed you all four ways. So first was we can check required checkbox on field level while creating field. Then page layout validation rule and trigger. So I hope you understood all four ways to make a field required in Salesforce. If you want to watch more Salesforce training videos you can go to description of this video. Thank you for watching this video.