Validation Rules

,

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.
Go to the development page for the Position record. Click New in the Validation rules section to bring up the page shown below.



Figure 62. Defining validation rules


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.
Select the Educational Requirements field and click Insert. Enter “” for the literal text.

6.
Enter You must specify an educational requirement for this position as the error message, select the Field choice for error location, and Educational Requirements as the Field. Click Save.

7.
Go to the Positions page, edit a record to change any value and attempt to save the record. Since the values for the Educational Requirements picklist have not been populated, you will see your validation in immediate action, as shown below.



Figure 63. Your validation rule in action


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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.111.41