Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Get Started with Validation Rules

Learning Objectives

After completing this unit, you’ll be able to:

  • Describe validation rules and use cases.
  • Create a simple validation rule.

What Are Validation Rules?

You rely on data to run your business, and Salesforce stores a lot of that data. When that data is wrong, it’s harder to make good decisions and deliver value to your customers. That’s where validation rules come in.

Validation Rules are powerful tools on the Salesforce Platform that are used to enforce data quality and ensure that the data entered into your Salesforce org meets your requirements. They act as a safeguard, preventing users from saving records that do not follow your predefined business rules. When a user attempts to save a record, Salesforce evaluates the defined criteria in the validation rule. If the criteria are met, the record is blocked from being saved, and an error message is displayed to the user, prompting them to correct the data before proceeding.

Use Cases for Validation Rules

Validation rules are flexible by design, which means there’s no shortage on how they can be used. Here are some examples of how validation rules can help your business. 

Data Format

Does your data have length, range, or format requirements? Validation rules help you keep your data clean.

Business Process Enforcement

Records in Salesforce often go through a lifecycle. For example, a Case might start out as new, get assigned to a support agent, and get resolved. At each stage of this process, certain fields might be required or only certain values should be used.

Compliance and Regulation

For organizations in regulated industries, such as healthcare or financial services, validation rules help ensure compliance with industry standards and regulations. These rules can be set up to verify data against specific criteria, helping organizations meet their legal and regulatory obligations.

Mechanics of Validation Rules

Formulas evaluate the criteria for a validation rule. If the formula results in TRUE, the error message will tell the user to correct their data. So, instead of telling the user what good data looks like directly, these rules cleverly describe the situations you definitely want to avoid.

Note

You don’t need to include IF(condition, TRUE, FALSE) in your formula. You can just use condition, since that already results in TRUE or FALSE!

Validation rules execute after your automation runs triggers and flows. This is important to remember because you could build automation that updates records with values that conflict with your validation rules. Doing so prevents your users from saving even when they aren’t making direct changes that violate your validation rules.

Create a Validation Rule

Ready to Get Hands-on with Validation Rules?

Launch your Trailhead Playground now to follow along and try out the steps in this module. To open your Trailhead Playground, scroll down to the hands-on challenge and click Launch. You also use the playground when it's time to complete the hands-on challenges.

Now that you know a little more about why validation rules are used, let’s create one. In this example, you create a new validation rule that requires the account number to be exactly eight characters if it’s populated. If it isn’t populated or if the length is eight characters, then we allow the record to be saved. 

  1. From Setup, click Object Manager.
  2. Click Account.
  3. In the left sidebar, click Validation Rules.
  4. Click New.
  5. Enter the following properties for your validation rule:
    1. Rule Name: ACT001_Account_Number_8_Characters
    2. Description: Account numbers must be exactly eight characters long when populated.
    3. Error Condition Formula:
AND(
  NOT(ISBLANK(AccountNumber)), 
  LEN( AccountNumber) != 8
)

d. Error Message: Account number must be 8 characters long [ACT001]

e. Error Location: Field, Account Number

6. To check your formula for errors, click Check Syntax.

7. Click Save.

When complete, your validation rule should look like this.

Validation rule edit screen showing all the values populated.

Now let’s see that validation rule in action.

  1. Navigate to the Sales app.
  2. Click the Accounts tab.
  3. Click New.
  4. Fill in the following fields:
    1. Account Name: Northern Trail Outfitters
    2. Account Number: 1
  1. Click Save.

The validation rule error message displays underneath the Account Number field. You can try changing the account number field to test different situations, such as no account number or an account number longer than eight characters.

Salesforce Account new record page showing an error message on the account number field and a balloon instructing the user to review the Account Number field.

Next, let’s look at some best practices to follow when building validation rules. 

Resources

Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기