Validation Rules in Salesforce | How to create it to restrict users from entering incorrect data

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you been struggling with validation rules for so long yes then don't worry I am here to help you out let's have a quick overview on validation rules and let's see what they are how they are created and what ones do you need to consider with validation rule so let's begin let's begin with what validation rules do validation rules verifies the data a user enters in a record to meet the organization's standard okay so to explain it to you I will take a simple example consider that you must have come across certain situations in which you want to control the data which your users enter to save a record and that situations might be like you want every opportunities amount to be greater than 10,000 you don't want any opportunity to be created in your cells all where the amount is less than 10,000 so in that situation you will create a validation rule okay let me take another example imagine your user is creating a lead to record or editing an existing lead recorder entering and entering an email address in the email field what you want is that whenever whenever email is entered into the lead record there should be phone number also otherwise email should not be entered yes there can be a situation like that so in that situation also in create validation rules okay let me take another example there is a situation when a user is creating an account record and the ownership is public so in that situation what you want is the annual revenues field should also be populated otherwise the record should not be created I mean like it should not be I'm not saying that should not be created I mean should not get saved basically and like and if it is private then annual revenue can be left blank or whatever the value it is but if the ownership of account record is public in that situation you want the animal revenue field to be populated so in that situation also will create a validation rule okay now let me explain you that what validation rule is and what it consists of validation rule it is basically a simple rule which gets evaluated or executed whenever a record gets saved like record gets saved when you are creating and when you are editing it so whenever you are saving that record of clicking on that Save button the validation rule on that particular object gets executed and validation would only consists of two things first formula or an expression which gets evaluated and this formula expression returns one of the two values true or false and if returns it and if this formula or expression returns a true value in that situation and error message gets displayed and the record doesn't gets saved but if this formula expression evaluates to false in that situation the record will get saved so what do you need to do is in order to control the data which are users entering to meteor of which your users are entering to create a record or to like to enter into that record to create a record or to basically edit that record entering that particular information and you want the data should be like there should be quality data and you want that data should meet your organization standards so in that situation you are creating validation rules so in that validation rule you'll simply write down a formula which will evaluate whenever the user is saving that record and that evaluation should be like like that formula or the expression should be created in a way that if this formula gets true like gets the value true or returns the value true then in that situation an error will be displayed and the record will not get saved and if that formula or expression evaluates to false then in that situation only the record gets saved so this is what the flow of validation rule is and this is what it consists of and it it is basically created to like keep you keep your data or like to like I mean maintain the data quality in your org and to want your users to enter the information that meets your organization's standard and yes you can create as many validation rules as you want on a single object then like if you have created three or five validation rules on a single object they'll be evaluated one by one after another and in whichever validation rules there the formula evaluates to true then that situation an error will be displayed to the user who is trying to save that record and he'll not be able to save that record until that problem gets solved and if all the validation rules like we are taking an example of five if all the five validation rules gets evaluated and returns a value five then in that situation the record will get saved now to explain you that how we will create a validation rule in our Salesforce or I will take two simple examples and that are the first one every opportunity record should have the amount fields value greater than 10,000 let's go and create it alright so we actually need to create the validation rule on opportunity objects so we need to go to the opportunity to object using setup and from setup we'll go to object manager and over you can see opportunity object here are the validation rules create new you need to take this active box if you want this validation rule to be active and if in any case you want a record to be created without this this validation rule or if you in any case if you want this validation rule to be disabled then you can simply edit it and uncheck this act actor checkbox and make it make it disabled yeah and over here you can write down the description and here is the place where you have to write down the formula or the expression which if evaluate to true will throw an error and which if like I mean if if it is evaluated as false and in that situation the record will get saved so I will insert the field an opportunity object I want a mount yes here is the amount field I'll insert it I don't have to write anything and I'll insert the operator I want this to be then 10,000 okay you must be wondering that why I have put like placed less than because if amount is less than 10,000 only that in that situation I want to throw they're not the opposite so I'll like like I mean set it as 10,000 and click on check syntax no error is found and here I have to write down the error message amount should be greater then 10,000 and I want to show it on a field if you can if you want to show it on top of the page you can show it but there's a little convention over here that if this validation rule involves only a single field then in that situation you should or you should prefer to show it after that field only and if there are more than one fields involved then show it on the top of the page click on save now we'll go to create an opportunity record and I'll set the amount as 8000 and that is less than 10,000 yeah and I will shut down first and closed it as 8 stages prospecting that's it save ok reveal do errors on this page amount should be greater than 10000 so this is how validation rules work but if I'll change it to 10000 or let's say more than 10000 that in that situation the record will get saved ah that seems so simple validation rules are very easy huh aha don't underestimate validation rules let's create the second validation rule a little complex so the requirement is that whenever a user is creating an account record or editing an account record and the ownership of that account is public then in that situation annual revenue field should not be empty and always be greater than 0 this is what you have to do now let's again go and create a validation rule so let's create the complex validation rule now will you again go to setup and then the object manager and in object manager will go to account over here we'll go to validation rules click on new and all revenue check and here will write down the expression which you want like which you want to check and for that will I mean what I'll do is first we need to check that the ownership field is equals to public or not so for that I'll use a function and it's not a condition over her conditional statement or something like that it's basically a function and here you can see the function menu where you can find many many functions which you can use in validation rule which will help you out to create I mean whatever validation you want to create like to meet your organization's standard for the data so initially on the very first node we'll use if condition and if you want to know that what all conditions are then you just have to click on that particular function and here you will find out that it's this functions information and if you want to know more about all of these functions in here is the link I would highly recommend you to check out this link so that you can I mean learn how to handle the complex validation rules so here we have used a function it like takes three arguments first is the logical test then value of true then value if false so logic in logical test we just have to provide the logical test that you want to perform for this if condition and over here we want to check that ownership is equals to public or not so I'll click on ownership and then insert operator equal and then public like this and over here I have to write down the value of true so like if the value is like if ownership is equals to public then what I want is that what annual revenue via an old revenue I am forgetting annual revenue is not equals to which is like this null and if it is not equals to null or let's say it's equals to null then in that situation it should return a value animal revenue is equals to null then it should return a value return a true value and it will if it will return a true value then the error will be displayed otherwise not and if ownership is not public then we'll simply pass false because we don't want any error to be displayed we want the record to get saved so we have passed falls over here and I will click on sex in takes before clicking on check sin takes let me tell you that there is something we are going to happen over here and let's see what it is Oh field ownership is a picklist field picklist fields are not only supported or are only supported in certain functions okay so let me tell you pick list fields cannot be matched or their values cannot be merged using equals to operator we need some special functions for that and that special function is is fake well okay I'll insert the selected function over here this is the actual function it takes two arguments one is the picklist field and another one is that X literal what this function does is that whatever bikal is failure you are passing and whatever takes literally were passing it just matches that is this picklist fields value is this takes literal or not and if it is this text literal then it returns two otherwise it returns false so in our situation I will copy ownership into the picklist field and in the text literal I'll copy public like this and I will remove equals two from here and I cut and paste it as a first argument for and now if this is I mean if this is this condition is true then this should evaluate but let me tell you one thing more there is a function called is null also so you can use that function to check whether the annual revenue is null or not so I just have to pass annual revenue into this function like this no and I will copy this and paste it over here so if ownership is equals to public and annual revenue is a Coast is null then in that situation it will turn true and the error message will be displayed otherwise it ownership is not public then it will return false record will get saved if ownership is public and it is not equal to null then it will return false and the record will get saved there is no error message shown over there okay like this so I've created a validation rule here is the formula is the error and a error location I want to set it as top of the page because there are more than one fields involved it's just a convention there is no compulsion to follow it but it's totally up to you click on save now I will go to my account object and I will create a new account record and I will set the name and all those things are like name account valid check yeah and I'll set the ownership as public an animal revenue is null and same review this error is on this page and revenue cannot be null for public companies okay let's see what happens when I set it as private save all the records gets created successfully now let's create another account record account ballot to and set the ownership as public and set the annual revenue as what do we want and say Oh account just created this is how you basically create some complex validation rules wasn't that so easy actually yes but still there are some points that you need to consider with validation rules so the first point validation rules gets evaluated a respective of the medium from which you are creating the requires yes it doesn't matter means that if you have created the validation rule from Salesforce classic or sales was lightning this will work only when you are creating the records from Salesforce classic or lightning these will work even if you are creating the records or editing the records from Salesforce one all from the api's or from any external application that has the integration with your Salesforce validation rules works everywhere these are basically the layers on your database which every record will like go into your database it which needs to pass validation rules it doesn't matter that they're coming from since was classic Salesforce lightning Salesforce one or from any other medium it needs to pass from these validation rules and if it doesn't then the error gets displayed on the platform from which we are creating the records the second point when one validation rule fails Salesforce continues to check all the validation rules on that object and displays all the error messages at once yes imagine you have five validation rules on a single object when you're creating that or like when you are creating a record of that particular object let's suppose that it has checked the first validation rule and it is checking now the second validation rule if there is an error then it doesn't happen that the third fourth and fifth validation rules will not be checked they'll also be checked on that same pass or in that same situation only and all of the error messages that will come from second till fifth or whatever like whatever the number of validation rules are on that a particular object and whatever energy you are facing from those validation rules all of those errors will be shown at once it will not be like that like now you have to pass the second validation rule now you will get the error of 4/4 while office validation rules they run at a whole how many of they are on a particular object and one more point whenever you need to create some records or import your data that can violate the validation rules which you have created in that situation you don't actually have to delete the validation rule you can just deactivate it using the checkbox like just uncheck that active checkbox on that validation rule and it will be deactivated ready to go what else this is over hit the subscribe button now with the notification belacan so you will be the first one to get notified whenever I do we do it's uploaded on this sales result Channel and on the sales social Channel I create and upload a video every week and if you're watching this video on Facebook or LinkedIn there's a link down in the description just hit that link go to the YouTube channel hit the subscribe button to watch me every week and learn from me yeah just hit the subscribe now it's free what are you waiting for see you next week then all right take care
Info
Channel: Salesforce Hulk
Views: 83,729
Rating: undefined out of 5
Keywords: Validation Rules, Salesforce, What Validation Rules in Salesforce and How to create them?, How to, What are, validation rule, create validation rule, example, best salesforce turorial, Shrey Sharma, salesforce tutorials
Id: 5-fEWo6b34U
Channel Id: undefined
Length: 18min 29sec (1109 seconds)
Published: Fri Nov 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.