Salesforce Validation Rules: How They Work and When to Use Them

Learn how Salesforce Validation Rules work, when to use them, and what data issues they prevent.

Table of Contents
See how Weflow enforces Salesforce data quality at the source, so your validation rules rarely need to fire.
Book a demo
Or use our free web app.
Validation rules catch bad data at entry — Weflow prevents it upstream by guiding reps to update Salesforce correctly.
See it live

What are Validation Rules?

Validation rules are important for any system, Salesforce included. They can prevent users from entering invalid data, which can cause errors and make your reports unreliable. Validation rules also prevent users from saving records if the rule returns an error, which helps ensure data integrity across objects in your Salesforce org.

Let's look at an example of how you might use a validation rule. Say you have a custom object that's related to your accounts, like "account history." When adding or updating information on this object, you always want to be sure that the user selects an account record as well (such as "account history"); otherwise things are going to get confusing fast! A validation rule will require users to include this information when adding a new record of type "account history," and it'll help ensure that all records have correct data moving forward.

Now that we've covered what a validation rule is and why it's useful, let's talk about how we create one in Salesforce!

‍

How do Validation Rules Work?

Unlike workflow rules, which can only evaluate a record when it’s saved, validation rules are evaluated every time the record is saved, including both before and after triggers.

If a validation rule evaluates to true, Salesforce displays an error message defined in the rule. The record will not be committed to the database until the error is fixed and all validation rules have been evaluated as false.

But if your trigger or workflow field update formula is set to fire before a save, you may get an error that your field has been updated by another process—even though it hasn't been yet! To avoid this issue, make sure formulas are set to run after the record is saved.

When to Use Validation Rules in Salesforce

You can use validation rules in Salesforce when:

  • You want to make sure users are entering correct data. For example, if you want to ensure a user enters only numbers between 1 and 10,000 in a certain field.
  • You want to prevent duplicate records. For example, if you don't want two contacts with the same name or two leads with the same email address.
  • You want to prevent users from saving records unless they fulfill certain criteria. For example, if you don't want people to save an opportunity unless they provide information about what the lead wants.
  • You want to make sure data is entered in a certain field before users can save a record. For example, if your company has sales targets for each region that can't be saved without a value in the target amount field for that region.
  • You want to make sure data is entered in a specific format before users save records. For example, if you have phone numbers that need to be more than 10 digits long but less than 15 digits long (since some phone numbers may have an area code).

‍

Examples of Validation Rules in Salesforce

As you've seen so far, validation rules can be used to ensure that a number is greater than a certain value, or that a date is after a certain date. They can also be used to ensure that a string (a series of characters) is the right length.

‍

Ensure anyone who fills the contact form, must fill out their email address

Here's another scenario: you're putting together a contact form for your website, and you want to make sure that anyone who fills it out has entered their email address.

You could do this with the following validation rule:

AND(ISBLANK(Email), NOT(ISBLANK(Website)))

The logic is simple: if the Email field is blank and the Website field is not blank, allow the user to proceed. If either of those two things aren't true—if both fields are blank or if the Email field is not blank—the rule will throw an error telling the user that they need to enter their email address in order to continue.

‍

Using LEN function

Here's another example of how you can use the LEN function in combination with the AND function to ensure that Account Name must always have more than 5 characters.

The AND function is one of the most common validation rules in Salesforce. To use it, you must combine it with a function like LEN (length) to indicate how many characters you want your string to be, and then include an error message that will pop up if someone doesn't meet the requirements.

AND(LEN(Name) > 5, false)

‍

Salesforce validation rules let you enforce the integrity of your data when it's entered.

Salesforce validation rules let you enforce the integrity of your data when it’s entered.

Validation rules check the data that is entered into a record, and ensure that it meets the standards specified by your business before you save the record to Salesforce. This means that you can prevent users from entering incorrect data into your Salesforce org in the first place.

‍

By
Daniel Schemmert

Daniel Schemmert is the Head of Growth at Weflow, where he's built the GTM engine from scratch. He spends valuable time talking to RevOps leaders about how they run pipeline, forecasting, and Salesforce. He's also the co-founder of RevOps Chat, the Slack community where 1,000+ RevOps practitioners share what's actually working inside their revenue orgs.

More articles by
Daniel Schemmert

Related articles

How to Measure RevOps Impact and Prove Its Value to Leadership

Learn how to measure RevOps impact, baseline metrics, and prove value to leadership and the board.

Where RevOps Should Report: CRO, COO or CFO

Decide whether RevOps should report to the CRO, COO, or CFO based on scope, neutrality, and needs.

What RevOps Should and Should Not Own: Defining the Mandate

Learn what RevOps should and shouldn't own, with tests to define the RevOps mandate.

Who Owns CRM Data Quality in a Revenue Team

Learn who owns CRM data quality: RevOps sets standards, reps update judgment fields.

How to Run RevOps Intake and Build a RevOps Roadmap

Learn how to run RevOps intake and build a roadmap with one queue, CRO ranking, and capacity rules.

RevOps Career Path: Roles, Skills and the Move From Analyst to Head of RevOps

Learn the RevOps career path, key skills, and how to move from analyst to Head of RevOps.

When to Hire Your First RevOps Person, and What They Should Own First

Learn when to hire your first RevOps person and what they should own before buying tools.

How to Build a Revenue Operations Function From Scratch

Learn how to build a RevOps function from scratch: audit first, hire right, and buy tools last.

RevOps Manager Responsibilities and Skills: What the Role Owns

Learn what a RevOps manager owns, key skills, and how the role differs from sales and marketing ops.

What Is Revenue Operations (RevOps)? Definition, Scope and How the Function Works

Learn what RevOps is, what it owns, and how the function runs across marketing, sales, and CS.

The Five-Quarter Board Report: Productivity per Rep, New Logos per Rep and New vs Existing Business

Learn which 5-quarter sales metrics to show your board: productivity per rep, new logos, new vs existing.

Board and Diligence Reporting for PE-Backed Sales Teams: Five-Quarter Trends From Pipeline Snapshots

Learn how PE-backed sales teams build five-quarter board and diligence reports from pipeline snapshots.