Stopping non-system administrators from changing account names with a validation rule

Often there is a need to restrict the updating of data from users within Salesforce CRM. A typical example is where account records are created according to an agreed process or naming convention, which requires verification by other users or systems within the organization.

In this recipe, we will construct a validation rule that prevents the changing of account name by users who are not logged in as system administrators.

How to do it...

Carry out the following steps to create a validation rule:

  1. Navigate to the account customization setup page, by going to Your Name | Setup | Customize | Accounts | Validation Rules.
  2. Click on New.

    Note

    Here, we are presented with the Account Validation Rule Edit page.

  3. Type Admins Only to Update Name in the Field Label textbox (upon clicking out of the textbox, the name changes to Admins_Only_to_Update_Name).
  4. Leave the Active checkbox ticked.
  5. Optionally, set the Description field to This validation rule is for stopping non-System Administrators from changing Account Names.

    Note

    Navigate to the Error Condition Formula section (as shown in the upcoming screenshot).

  6. Paste the following code:
    AND( 
      ISCHANGED( Name ), 
     
      $Profile.Name <> "System Administrator"
    )
  7. In the Error Message section, enter the text Only System Administrators are allowed to change the Account Name.
  8. In the Error Location option, select Field.

    Note

    Here, we are presented with the Field selection pick list (as shown in the following screenshot).

  9. Select the field Account Name (as shown):
    How to do it...
  10. Finally, click on Save.

How it works...

Having logged in as a user that does not have a system administrator profile and changing the name of an account record, the validation rule is activated and the record is prevented from being saved. Upon the attempt to save, an error message is displayed below the Account Name field stating Error: Only System Administrators are allowed to change the Account Name.

You can see what this looks like in the following screenshot:

How it works...
..................Content has been hidden....................

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