After studying this topic, you should be able to:
    Describe the use of system validation rules for data
    validation in Salesforce
    Explain the implications of required and unique fields
    in Salesforce
    Explain the use of custom validation rules for data
    validation
                                      Introduction
                                      †
Data validation tools are used to ensure accurate data is entered into
Salesforce by way of validation rules that ensure that what is
acceptable as new or updated data meets the conditions set. There are
two types of rules: system validation and custom validation.
System validation rules are set up on the field itself, by limiting field
length, requiring it be unique, or other simple requirements. Custom
validation rules are more complex and can contain formulas or criteria
that determine if data can be processed or rejected. A message is
displayed in the event that the right criteria is not met. This ensures
clean and accurate data is entered.
                                   Data Validation in Salesforce
                                   †
                  System Validation                                                Validation Condition & Error
    System validation is performed by                                              Condition and error message are
   Salesforce. For example, it ensures                                             specified for a validation rule. When the
that the data type is correct for a field.                                          condition formula is true, the error is
                                                                                   displayed.
                           Required Fields                                  Custom Validation Rule
A custom field can be made required so that                                  A custom validation rule can be used to
a record cannot be saved without specifying                                 perform a complex validation that
         its value during creation or update.                               involves one or more fields.
                                                      Unique Fields
                                            Text, email, and number fields can be
                                            marked as unique in order to prevent
                                              duplicate field values on records.
                                     Types of Data Validation
                                     †
          Validation rules are used to verify that the data being entered by users meet the
                 standards set by their organizations before a record can be saved.
              SYSTEM VALIDATION                                        CUSTOM VALIDATION
These are basic standard rules enforced by Salesforce in   These are rules that can be created and incorporated
            order to maintain data quality                   with functions and logic in order to meet more
                     and integrity.                            business-specific validation requirements.
                              Order of Processing Rules
                              †
System and Custom Validation rules are run first, before other types of processing rules.
       1                  2                3                  4                      5
Validation        Duplicate and      Auto-Response        Workflow           Escalation and
  Rules            Assignment            Rules            Rules (with        Entitlement
                      Rules                               immediate             Rules
                                                           actions)
System Validation Rules
‡
    Develop your career with Salesforce Training and Certification Preparation
                                   System Validation Rules
                                   †
                 System validation rules are built-in and enforced by Salesforce.
         DATA TYPE                          FIELD LENGTH                   TRIGGERED ON SAVE
Ensures data type is correct for       Validates field length on text,   Enforced immediately on record
  the field (e.g. email, phone,          currency and number fields         save, prior to workflows or
      currency, number)                                                        process builders
                        System Validation Rules
                        †
Users can configure system validation rules such as setting character limits, making
                    fields required and/or unique, and others.
                              Types of Standard Validations
                              †
 DATA TYPE VALIDATION                  REQUIRED FIELDS                  UNIQUE FIELDS
A value of the correct data type    A field cannot have an empty   The same field value should not
       must be entered.                        value.                exist in another record.
                                                                    It applies to Text, Number, and
                                                                    Email fields.
                                                                    A Unique Text field can be
                                                                    configured to be case-sensitive
                                                                    or case-insensitive.
                    Defined Length for Field
                    †
Users can enter only up to the allowed number of characters defined for text
                              or number fields.
                Errors from System Validation Rules
                †
System validation rules display error messages that describe the cause of the error
                   and/or provide information to resolve them.
Options for Marking Fields
†
             REQUIRED
             Fields can be marked required, so no matter which
             user is entering or if being loaded through a tool,
             an error will occur if the field is blank.
             UNIQUE
             Fields can be marked as unique to not allow
             duplicate values across the records of the object.
Implications of Required Fields
†
               ERROR ON SAVING
               A record cannot be saved without a value,
               including when created or updated through Data
               Import Tools.
               AVAILABLE ON PAGE
               Field will be added to all page layouts and cannot
               be removed.
               LIMITATION
               Cannot be used for all field types e.g. text
               area (long)
                                  Types of Required Fields
                                  †
            UI REQUIRED FIELDS                       METADATA REQUIRED FIELDS
Required at the UI level only                  Required at both the UI and API level
Configured in the page layout editor            Configured at the field level
Required only at the page layout level         Required everywhere in the system all the time
Field can be removed the page layout           Field cannot be removed from the page layouts
Not required in data imports                   Required in data imports
                  Error Message and Required Fields
                  †
When required fields are not populated, error messages are displayed on each field as
            well as a section which summarizes all errors on the page.
Implications of Unique Fields
†
              PREVENT DUPLICATES
              Prevent duplicate values on the fields across all
              records of the object.
              LIMITATION
              Only certain field types can be marked unique,
              e.g. text, email, and number.
              CASE SENSITIVE
              Case sensitivity can be set for text fields.
                         Error for Duplicate Entry
                         †
When a field on a record is marked as unique, and a value entered for that field already
 exists, the validation rule fires an error which prevents the record from being saved.
Custom Validation Rules
‡
    Develop your career with Salesforce Training and Certification Preparation
                                    Custom Validation Rules
                                    †
    Custom validation rules are custom rules configured on an object that validate field
   values before a record is created or updated to prevent users from saving invalid data.
 COMPLEX VALIDATION                      ORDER OF EXECUTION                     CREATION
   Used for custom complex                Enforced prior to any other     Defined using a formula or
validation rules that can involve       processing rules, Workflows or   expression and return true or
 one or more fields (standard                      Processes              false, with the defined error
           or custom)                                                     message displaying when
                                                                                 returned true
                        Custom Validation Rule Considerations
                        †
                                                       APPLIES ON DATA IMPORT
                                 ENFORCEMENT           If validation rules are used in an object, it will be used
          Validation rules apply to new or existing    to check against imported records. If a violation
      records even if fields referenced in a rule are   occurs by meeting the criteria set in the error
      not displayed on a page layout or an API call.   condition formula field, records cannot be saved.
        ERROR MESSAGE                                                          REGEX
   An error message can be                                                     Validation rules can be used to
  displayed at the top of the                                                  enforce formatting of input
page or next to the field that                                                  through the REGEX formula
   failed the validation rule.                                                 function.
                 Example of using a Validation Rule
                 †
The Account Id custom field of an account record is populated and any changes made
                        on this field should be prevented.
                                                     In order to meet the requirement
                                                     above, a custom validation rule can
                                                     be created on the Account object.
                †Parts of a Custom Validation Rule
There are two main parts in a custom validation rule: the error condition formula
                              and error message.
                                            This is an example of a validation
                                            rule that prevents the changes on
                                            the existing custom Account ID field
                                            value from being saved.
              1. Error condition
                   formula                  When the specified condition returns
                                            true while saving a record, the error
                                            message is displayed to notify the
                                            user that the field value needs to be
                         2. Error message   corrected.
Validation Rule Considerations
†
               CONTINUOUS VALIDATION
               When one validation rule fails, Salesforce continues to
               check other validation rules on that field or other fields n
               the page and displays all error messages at once.
               ACTIVITIES ON LEAD CONVERSION
               If validation rules exist for activities and you create an
               activity during lead conversion, the lead converts but a
               task isn’t created.
               LEAD CONVERSION VALIDATION
               Validation rules are only enforced during lead conversion
               if validation and triggers for lead conversion are enabled
               in your organization.
Validation Rule Considerations
†
               CAMPAIGN HIERARCHY
               Campaign hierarchies ignore validation rules.
               RECORDS FROM WEB
               Salesforce runs validation rules before it creates records
               submitted via Web-to-Lead and Web-to-Case and then
               creates records that have valid values.
               MASS TRANSFER TOOL
               Validation rules continue to run on individual records if
               the owner is changed. If the Mass Transfer tool is used to
               change the ownership of multiple records, however,
               validation rules don’t run on those records.
           Validation Rule Preventing Saving of Record
           †
Below shows the validation rule in action where it displayed the error and prevented
 the record from being saved after an attempt to change the Account Id field value.
                                       Learn More
                                       †
Require Field Input to Ensure Data Quality
Custom Field Attributes
Validation Rule Considerations
Define Validation Rules