In this chapter, you have learned about ways to insure the integrity of your all-important data. You can achieve this goal by limiting the values available for entry by a user, either with picklists or relationships, or by eliminating the need for users to enter data by creating the data with a formula field. This last section gives you one more tool for enforcement: validation rules.
Validation rules are defined in much the same way as formulas, with access to the same helpers and functions. But a validation rule works in a more specific way:
Uses an Error Condition Formula that evaluates to either TRUE or FALSE
Prevents the user data action that spawned the validation if the formula evaluates to FALSE
Displays a custom error message for the user, either at the top of the page or next to a specified field, in the case of a false condition
Validation rules are pretty straightforward, so defining one teaches you enough to define many more. The following validation rule makes sure that a Position record always has a value for the Education Requirements picklist.
1. | |
2. | Enter Required education specification for the Rule Name and give the rule an informative description. |
3. | Select the ISPICKVAL function, which compares the value in a picklist with a literal, and click Insert Selected Function. |
4. | Highlight the picklist_field in the function and click Insert Field to bring up the dialog box to select a field. |
5. | |
6. | |
7. |
Note that the validation is executed whenever a user attempts to insert or change a record. Existing records are not checked to see if they pass any new validation checks. This implementation presents a caution as well as some flexibility. If you have a validation that you absolutely require for all data, take care to implement it before data is added to the object. Conversely, if you do not want to force validation for some records, you can always make a validation rule inactive on the detail page for the validation rule.
An attempted save of a record can result in more than one validation error, in which case all errors display.
18.119.163.238