New

Experience Smart HR with Horilla Mobile App

Google Play Store Google Play Store
Home / Blogs

How to Set Up a Validation Rule in Salesforce

CRM
·

October 28, 2025

how-to-set-up-a-validation-rule-in-salesforce

Ensuring data accuracy in Salesforce plays an essential role in keeping the database organized and running efficiently. One way to enforce data integrity is by using Validation Rules. These rules ensure data accuracy by enforcing specific conditions that must be satisfied before a record is saved.

In this blog, we will explain what validation rules are, their benefits, and how to create one step by step.

What is a Validation Rule in Salesforce?

A Validation Rule in Salesforce verifies that the data entered in a record satisfies specific criteria before it is saved. If the data does not meet the specified conditions, Salesforce displays an error message, and the record cannot be saved until the issue is fixed.

Key Components of a Validation Rule

  1. Formula or Expression – Defines the condition that must be met
  2. Error Message – Displays a message when the condition fails
  3. Error Location – Determines where the message appears (field-level or top of the page)

Benefits of Using Validation Rules

  • Ensures Data Accuracy – Prevents users from entering incorrect or incomplete data
  • Reduces Errors – Stops mistakes before they are saved into the system
  • Enforces Business Rules – Ensures compliance with company policies
  • Improves Reporting – Maintains clean and structured data for better analytics

How to Create a Validation Rule in Salesforce

Follow these steps to create a Validation Rule in Salesforce:

Step 1: Go to Object Manager

  1. Click on the Setup menu.
  2. In the Quick Find box, search for the object where you want to apply the validation rule (e.g., Account, Contact, Opportunity).
  3. Click on the object name to open its settings.

Step 2: Navigate to Validation Rules

  1. In the left panel, click on Validation Rules.
  2. Click New to create a new validation rule.

Step 3: Define the Validation Rule

  1. Enter a Rule Name – Provide a meaningful name for the rule.
  2. Enter the Formula Expression – Write the formula that defines the condition for validation.

Step 4: Add an Error Message

  1. In the Error Message section, enter the message that will appear when the rule is triggered.
  2. Choose where the error message should appear:
    • Field Level – The message will appear next to a specific field.
    • Page Level – The message will appear at the top of the page.
  3. Click Save to activate the validation rule.

Step 5: Test the Rule

Ensure that your validation rule for Number of Employees in the Lead object is working correctly. The rule should enforce that the Number of Employees must be greater than zero.

Test Case : Enter Incorrect Data

  • Try creating a lead with Number of Employees = 0 or leave it blank.
  • Click Save.
  • The system correctly displays the error message: “Number of Employees must be greater than zero.”

Making a Field Required Using a Validation Rule

While Salesforce allows fields to be marked as required at the field level, sometimes you may need a Validation Rule to enforce conditional requirements.

For example, if you want to make the Phone field required only when the Lead Source is “Referral,” you can use the following validation formula:

AND(ISPICKVAL(LeadSource, “Referral”), ISBLANK(Phone))

  • Error Message: “Please enter a phone number when Lead Source is set to ‘Referral’.”

This rule ensures that users must enter a Phone Number whenever they select Referral as the Lead Source.

Conclusion

Validation Rules in Salesforce help maintain high-quality data by enforcing business logic and preventing incorrect entries. By following the steps outlined in this guide, you can create custom validation rules that improve data integrity and streamline workflows.

Using the right validation rules ensures that your Salesforce system remains reliable, accurate, and efficient for all users.

Horilla Editorial Team Author

Horilla Editorial Team is a group of experienced writers and editors who are passionate about HR software. We have a deep understanding of the HR landscape and are committed to providing our readers with the most up-to-date and informative content. We have written extensively on a variety of HR software topics, including applicant tracking systems, performance management software, and payroll software etc. We are always looking for new ways to share our knowledge with the HR community. If you have a question about HR software, please don't hesitate to contact us.