From the course: Salesforce Administrator Cert Prep: 4 Collaboration, Data Management and Automation

Data validation tools

- [Instructor] Okay so an important part of data management are data validation rules. And I've pulled up in the online help for Salesforce a page that's very critical in your learning of how to create validation rules and it's called examples of validation rules. If you just search this or search it within the online help you'll be able to find this page here. And this contains links to a lot of different sample validation rules that you can create. And this is really a good way to learn how to create validation rules and on the administrator exam, you don't have to enter the code for an actual validation rule fortunately, and this the closest you'll come to doing actual coding as an administrator on the platform, but you do need to understand what validation rules are and what they're used for and how this relates to data management. And so if I click through to some of these sample validation rules, for instance I'm just going to click on the sample user, role, and profile validation rules, there's good examples throughout that give you the code for different scenarios, and so for instance you could set a discount percent does not exceed role-based limit, and as you can tell there's some pretty significant code here. One that I want to use as an example, pulling from or leveraging one of these examples into our own Salesforce Org is this one that says that only the record owner can change a field. And so the description of this is that it ensures that only the record owner can makes changes to a custom field, in this example they're making a change to a custom field called personal goal. We're going to do a different field, and change this to meet our needs to be able to demonstrate how to do a validation rule. So if I copy this from this sample and then I go to a contact record, let's say that on our contact record we want to lock down a field to where only the record owner can make a change and so for instance let's say we want to lock down this Twitter profile field so that only the owner of this contact record can change that value and not someone else, such as myself, although I can see this contact record I'm not the owner, Jim Doe is. And so in order to access validation rules of foreign objects you can click on this fly-out menu here and click validation rules, and this brings you to the contact validation rules screen which is also available in the setup under the particular object that you're interested in, and all objects will have an option for validation rules, so here's for accounts, but we're dealing with contact, so clicking validation rules will take us to the contact validation rules screen, and it gives you a little detail, and then here is the quick tips link that takes you to that same page that I actually pulled up at the start of this lecture, and these are useful sample validation rules. So I'm going to click new to create a contact validation rule and I'm going to call this rule only owner can change twitter profile, and I've given this a description as to what this validation rule accomplishes, because a lot of times the rule name is not descriptive enough to remind you of what this rule is about, it's just helpful for those that follow you in administering the platform that you're on right now to give them further guidance on what these various validation rules accomplish and why they're there. And then you notice as well that this is checked to be active by default, and so now before we get into the filled in search and operators and functions, we're going to just paste our sample code for our validation rule and this contains in it at the start an and statement. And so this and statement is a function, and you can find it here on the right and it gives you further details as to what an and function is and so it gives an example of an and, and then inside the parenthesis are two or more logical statements, and so it checks whether all arguments are true and returns true if all arguments are true. And so the two arguments that it contains, this first one before the comma is checking to see if this particular field is changed, and so we mentioned that we were pulling from that sample code, but instead of using personal goal we're going to change that to Twitter profile. The custom field that we're interested in on our contact record to where only the owner of the contact can change is called Twitter profile, and so this is a custom field and so after the Twitter underscore profile we'll see underscore underscore C, and this is the API name that I've mentioned in lectures, and so for that custom field, and for any custom field, you'll have underscore underscore C, and so for validation rules, when you're dealing with custom fields you should see that underscore underscore C. And so then this other part of this validation rule, we can just leverage from our example, and so the owner of this contact, and this operator here, this less than and greater than sign, what that actually means is not equal. So here are the different operators that are available, and so if you're not sure about one, some of these may be confusing to you, like less than or equal or greater than and equal or the double ampersand is and or the double pipes are or, and so like I was mentioning this is really the most complexity and code-based things you'll do as an administrator, and so we're not going to belabor everything around massive validation rules, which they can get really complex, but we're going to create one to show you how it works and then talk a little more about how this relates to the exam. Once we think that we're done with our validation rule, you click check syntax. So now we've got an error here, and this is kind of a common experience, and even when you pull something from an example such as I did there's a field called owner that does not exist, and so it says check spelling. So I'm going to click the insert field button, and so for contact, I'm going to enter the owner ID, I've actually found not a really good example of a validation rule, and so it's good to know how to troubleshoot these things, and so what I did was I clicked on the insert field, and then this navigates you through these different options, and so the contact and then this arrow sign here points to this next box, and then I found the contact owner. What we're verifying here is that the owner of this contact record, that their ID, if it's not equal to the current user's ID in Salesforce, then it'll throw an error. And so we're going to check syntax again, and now we've got this validation rule working correctly. So next we've got to enter the error message so that if this validation rule evaluates to true, meaning that if the Twitter profile custom field is changed and the owner ID of the contact is not equal to the current user that's changing this field, then we need to throw an error. And we're going to give them an error message and so we're going to say only the contact owner may change the Twitter profile field for the contact. And then for the arrow location we can have that appear at the top of the page, but a lot of times it's helpful to have this appear at the field in question, and so we're going to have the error display right on the Twitter profile custom field, and then click save. So now we've created a validation rule and it's active, and so now if we go back to our contact record, and I'm going to go ahead and refresh this window to pull in a fresh copy of this contact record, so now I am not the owner of this contact, so if I try to change this Twitter profile and click save, it throws the error from our validation rule that we just created. It says that we need to review all error messages below to correct our data. And that's a generic validation rule error that appears at the top of the page because the error itself may display on a field that's offscreen, and they need to scroll down, so that helps give the user some clue as to that there's a problem. And then they can find the error here, 'cause we specified this specific error to display with the field in question. So it's saying only the contact owner may change the Twitter profile field for the contact. So now if I cancel out of that, if I go in and edit this validation rule and deactivate it and click save, the validation rule's no longer active. I should be able to come in here and make my Twitter profile change on a contact record I don't own and click save, and I've saved successfully. So now you see that this is not a valid Twitter profile, obviously, and so that Twitter profile field is a URL field that we created in a previous lecture, and so you could do additional validation rules to not only block someone that's not the owner of this contact from changing or entering the Twitter profile, you could also add validation to confirm that the resulting URL contains twitter.com for instance. The main things to realize though for data management as it relates to the admin exam, is that all validation rules apply to all new and updated records for an object. And it's even if the field that's referenced in the validation rule is not included in a page layout. So even if for instance a field is not displayed in the page layout, validation rules will verify and will block bad data entry, and so you probably wonder well how would you enter bad data if it's hidden from a page layout, and so how that could occur for instance is if you were to be making revisions to data through a list view, or even through the data loader, it's important to realize that the data loader respects validation rules and list view edits respect validation rules and so you may be questioned on the exam related to if validation rules will fire even if a field is not visible on a page layout, and that would be that validation rules are respected and also respected via data loader and even for any integrations as well, so that if there's any integrations with Salesforce and other systems, and those other systems are making changes through API calls to different field values, it will trigger errors if the data that's coming into Salesforce does not comply and pass the validation rules. So with we've now covered data validation tools on the administrator study guide, and that has to do with validation rules. Next we're going to be talking about data backup in Salesforce and that'll be the last lecture in the data management section.

Contents