Data validation

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
  • Dependent picklists

Data validation rules

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:

  1. Salesforce executes the validation rules and only if all data is valid, is the record then saved.
  2. For any invalid data, Salesforce displays the associated error message without saving the record.

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.

Note

Even if the fields referenced in the validation rule are not visible on the page layout, the validation rules still apply and will result in an error message if the rule fails.

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.

Note

Validation rules are listed in the Validation Rules related list.

As shown, to begin adding a new validation rule, click on the New button in the Validation Rules section:

Data validation rules

Now enter the properties of your validation rule that should include:

Field Description Section

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.

Error Condition Formula Section

The formula that is entered here forms the expression used to validate the field

Error Message Section

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:

  • Top of Page
  • Field

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.

Note

If the error location is set to a field that is later deleted or a field that is read only or not visible on the page layout, Salesforce automatically changes the error location to Top of Page.

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()

Note

An error message will be displayed to the user if the formula evaluates to TRUE. So, the formula should be written so that the condition that should be avoided is written into the formula.

An example error message for this validation rule is Close Date Must Be a Future Date.

Dependent picklists

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 picklists

Dependent and controlling picklists

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:

Dependent and controlling picklists

Now click on New and then choose a Controlling Field and Dependent Field:

Dependent and controlling picklists

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:

Dependent and controlling picklists

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:

Dependent and controlling picklists

To change the values in your view, you can:

  • Click on View All to view all available values at once.
  • Click on Go To and choose a controlling value to view all the dependent values in that column.
  • Click on Previous or Next to view the values in columns that are on the previous or next page.
  • Click on View sets of 5 to view 5 columns at a time.

Now optionally, click on Preview to test your selections and then click on Save.

Dependent picklists considerations

The following are the dependent picklists considerations:

Standard picklist fields

Standard picklist fields can not be defined as a dependent list. They may only be set up as a controlling field.

Default values

You can set default values for controlling fields, but not for dependent picklists.

Converting fields

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

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.

Page layouts

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.

Note

Make sure controlling fields are added to any page layouts that contains their associated dependent picklists. If the controlling field is not on the same page layout, the dependent picklist shows no available values

Record types

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.

Importing data

The import wizards do not consider field dependencies. Therefore, any value can be imported into a dependent picklist field regardless of the value imported for a controlling field.

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

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