In the previous chapter, we looked at how we can set the required field and auto number field properties on custom fields to help improve the quality and maintain the data integrity of records in the system.
Salesforce also provides other data validation mechanisms such as:
Data validation rules can be applied to both custom and standard fields and are used to verify that the data entered in a record meets the criteria you have specified before the record can be saved.
Validation rules contain a formula or expression that evaluates the data in one or more fields and returns a value of either True or False.
The logic that is used for validation rules is to seek an error condition, upon which, a pre-configured error message is shown to the user whenever the formula or expression returns a value of True.
When validation rules are defined for a field or set of fields, the following actions are fired when the user creates a new record or edits an existing record and then clicks the Save button:
You can specify the error message to display when a record fires the validation rule and also where to display it. For example, your error message can be The close date must occur after today's date. You can choose to display it near a field or at the top of the page. Like all other Salesforce error messages, validation rule errors are displayed in red text and are preceded by the word Error.
Validation rules apply to all new and updated records for an object.
If your organization has multiple page layouts for the object on which you create a validation rule, you should verify that the validation rule operates as expected on each layout. Also if you have any data integrations that affect that object, then you should also verify that the validation rule operates as intended.
To begin using validation rules, follow the path Your Name | Setup | (App Setup) | Customize.
For standard objects select the appropriate activity, standard object, or users link from the menu, and click on Validation Rules.
For custom objects, click on Your Name | Setup | (App Setup) | Create | Objects. Now select the custom object.
As shown, to begin adding a new validation rule, click on the New button in the Validation Rules section:
Now enter the properties of your validation rule that should include:
Add a Rule Name which is a unique identifier of up to 80 characters with no spaces or special characters such as extended characters.
The Active checkbox which is used to set that the rule is enabled.
Fill in the Description field which is an optional 255 character or less textbox that you can set to describe the purpose of the validation rule.
The Error Message field is the text to be displayed to the user when a record update fails the validation rule.
The Error Location is used to determine where on the page the error is displayed to the user. Options available are either:
The Top Page option sets the error message to be displayed at the top of the page. To display the error next to a field, choose the Field option and then select the appropriate field.
If the error location is a field, the validation rule is also listed on the detail page of that field.
You can click on Check Syntax to check your formula for errors and finally click on Save to finish or Save & New to create additional validation rules.
As an example, the following shows an opportunity validation rule to ensure that users cannot enter a date in the past into the Close Date field:
The formula would be: CloseDate < TODAY()
An example error message for this validation rule is Close Date Must Be a Future Date.
Dependent Picklists help to make data more accurate and consistent by applying filters.
A dependent field works in conjunction with a controlling field to filter its values. The value chosen in the controlling field affects the values in the dependent field.
Here we see the field Speaker Status being controlled by the field Speaker Event Status:
Dependent and controlling picklists work in conjunction where the value chosen in the controlling picklist dynamically changes the values that are available in the dependent picklist.
Both controlling and dependent picklists are indicated on edit pages by an icon. By hovering the mouse over these icons, users can see the name of the controlling or dependent picklist.
To define a dependent picklist, navigate to the fields area of the appropriate object:
For standard objects, follow the path Your Name | Setup | (App Setup) | Customize. Now select the appropriate object from the Customize menu and click on Fields.
For custom objects, follow the path Your Name | Setup | (App Setup) | Create | Objects. Now select one of the custom objects in the list.
For custom task and event fields, follow the path Your Name | Setup | (App Setup) | Customize | Activities | Activity Custom Fields.
Now click on Field Dependencies in the Custom Fields & Relationships section as shown next:
Now click on New and then choose a Controlling Field and Dependent Field:
Click on Continue to display the next screen where you are presented with the field dependency matrix to specify the dependent picklist values that are available when a user selects each controlling field value.
The field dependency matrix lets you specify the dependent picklist values that are available when a user selects each controlling field value. The top row of the matrix shows the controlling field values, while the columns show the dependent field values.
Using this matrix you can include or exclude values. Included values are available in the dependent picklist when a value in the controlling field is selected and excluded fields are not available.
Here you can include or exclude values by performing the following:
Double-click values to include them. Included values are then indicated with highlighting. (Double-clicking again any highlighted values will then be excluded).
To work with more than one value you should use the Shift key and click on each value to select the required range of values as shown next:
After selecting the values, click on Include Values to make the values available, or click on Exclude Values to remove them from the list of available values.
You can also use Ctrl key and then click individual values to select multiple values. Again, clicking on Include Values makes the values available, or clicking on Exclude Values removes them from the list of available values. By clicking a column header you can select all the values in that column:
To change the values in your view, you can:
Now optionally, click on Preview to test your selections and then click on Save.
The following are the dependent picklists considerations:
Standard picklist fields can not be defined as a dependent list. They may only be set up as a controlling field.
When converting existing fields to dependent picklists or controlling fields, this can be done without affecting the existing values in records. Only for changes going forward are the dependency rules applied to the updates to existing records or new records.
Field-level security settings for a controlling field and dependent picklist are completely independent. Therefore, you must manually hide a controlling field whenever its related dependent picklist is hidden.
For best practice and improved user visibility, make sure the dependent picklist is lower on the page layout than its controlling field.
If a dependent picklist is required and no values are available for it based on the controlling field value, users can save the record without entering a value. In this scenario, the record is saved with no value for that field.
The values in controlling fields are determined by the pre-selected record type and the values in dependent picklists are determined by both the record type and the selected controlling field value.
The values available in dependent picklists are, therefore, an intersection of the pre-selected record type and subsequent controlling field selection.
18.227.111.33