Salesforce has many rules in place out of the box that help users achieve their goals on the platform. In our Rules of Salesforce: Part 1 post, Sharing Rules, Escalation Rules, and Assignment Rules were highlighted as ways to obtain, view, and move data through a standard workflow with plenty of room for customization. This post will focus on three more rule types that can be found in Setup: Validation Rules, Duplication Rules, and Matching Rules. All three of these rules help to keep data clean and your Salesforce instance functional.
Validation Rules
Validation Rules can be found on every object in Salesforce and are used as a way to keep data set to a specific standard or criteria before a record can be updated or saved. Validation rules contain formulas that, if True, will prevent the record from being saved. They also come with an error message that will display to the user the reasoning for the rule preventing a save of the record to help make the field or fields in question compliant with requirements. The error message can display either at the top of the record or at the field in question. Validation rules are the first rule type processed by Salesforce when records are saved and all validation rules are run even if the first one fails, allowing for every error on the record to display at once. Limits per object vary by edition, with Professional being capped at 20, Enterprise and Developer at 100, and Unlimited and Performance editions being allowed 500 validation rules per object.
To create a validation rule, go to Object Manager in Setup and select the object you wish to add a rule to. Once the object is selected and you land on the Details page, scroll to the bottom of the left-side menu to find Validation Rules. Clicking the link will take you to the list view of all created validation rules. In the top right, click the “New” button to begin the creation of a new rule. The page for rule creation will require a rule name, error message, formula, and location of the error message. There is a “Check Syntax” button to validate that the formula that’s put in is functional. Once all of this is filled out, click “Save” at the top or bottom of the page to create the rule. Considerations for validation rules include editing restrictions for certain profiles, ensuring certain values are added to the record before saving dates or changing stage or status, and even containing the length of certain fields.
Duplicate and Matching Rules
Duplicate Rules and Matching Rules work in tandem in Salesforce to prevent duplicate records of an object to be saved in Salesforce. Each matching rule is assigned to a duplicate rule to be enacted when records are attempted to be saved. Out of the box, Salesforce comes with standard matching rules for Contact, Accounts, and Leads. The standard matching rules focus a lot on name, phone number, email, address, and company and will compare existing records’ values to those of a record being created. The duplicate rules can use one matching rule at a time although multiple matching rules can be active at once.
To create a new matching rule, search for “Matching Rules” in the Setup Quick Find box. They are found under Duplicate Management. After selecting Matching Rules, the landing page will display in a list view all of the current matching rules in the org. To create a new rule, click the “New Rule” button in the top bar of the list view. The first page will ask you to select an object to apply the matching rule to from a picklist. After the object is selected, click “Next” to be taken to the next screen to complete the rule creation. Give the rule a name and then select the fields to use to compare values. Most fields will be looking for exact matches, but a fuzzy match option is available for a few fields. If needed, set the filter logic for the rule and click “Save” at the top or bottom of the page. Once back to the list view, click “Activate” to the left of the rule you wish to make available for use with the duplicate rules.
For duplicate rules, it is the same as matching rules, but when you click the “New Rule” button, a picklist appears for you to select the object before beginning. Once the object is selected, you will be taken to the creation page where the rule will need a name and a decision to be made on the use of sharing rules in relation to the rule. In the “Action” section, choose whether to allow the records to be saved on creation or after editing and whether to provide an alert to the user. In the next section, select your Matching Rule. This is also where a newly created rule will be selected if you are updating an existing duplicate rule. There will be a final option to set criteria for the duplicate rule to run, but once you have completed all the fields, click “Save” to save the record.
Having the option out of the box for so many rules to set and create a customized workflow is one of the things that sets Salesforce apart as a leading CRM. Being able to prevent bad or duplicate data from entering your org at all is a great way to keep metrics and reporting accurate.