All posts
how-to May 31, 2026 11By RevKit Team

Salesforce Validation Rules: The Complete Guide

Salesforce validation rules from scratch — formula syntax, common patterns, error message best practices, and the 10 rules every B2B org needs.

Salesforce Validation Rules: The Complete Guide

Validation rules are the most underused data quality tool in Salesforce. Most orgs have a handful of them — usually added reactively after someone entered garbage data. The orgs with clean data have 20-40 rules built intentionally, covering every object where data quality matters.

This guide covers the formula syntax, the patterns that work, and the 10 rules every B2B org should have.

Estimated read time: 11 minutes

What validation rules do

A validation rule fires when a record is saved. If the formula evaluates to TRUE, Salesforce blocks the save and shows an error message. If FALSE, the save proceeds.

The formula is written in Salesforce formula language — the same syntax used in formula fields.

Formula syntax basics

The formula must return TRUE (block) or FALSE (allow).

AND(
  ISPICKVAL(StageName, "Closed Won"),
  ISBLANK(CloseDate)
)

This blocks saving a Closed Won opportunity without a Close Date.

Key functions:

  • ISBLANK(field) — true if field is empty (works on text, lookup, date)
  • ISNULL(field) — true if field is null (use ISBLANK for text fields)
  • ISPICKVAL(field, "value") — true if picklist equals value
  • NOT(condition) — inverts the condition
  • AND(a, b) — both must be true
  • OR(a, b) — either must be true
  • LEN(field) — length of text field
  • REGEX(field, "pattern") — matches a regex pattern
  • ISNEW() — true only on record creation
  • ISCHANGED(field) — true if field value changed on this save

Error message best practices

The error message is what the user sees. Make it actionable:

Bad: "Validation error" Good: "Close Date is required when Stage is Closed Won. Please enter the date the deal closed."

Rules for good error messages:

  1. Tell them what's wrong
  2. Tell them what to do
  3. Don't use technical field API names (use labels)
  4. Place the error on the specific field when possible (not just at the top)

The 10 rules every B2B org needs

1. Close Date required on Closed stages

AND(
  OR(ISPICKVAL(StageName, "Closed Won"), ISPICKVAL(StageName, "Closed Lost")),
  ISBLANK(CloseDate)
)

Error: "Close Date is required when closing an opportunity."

2. Amount required on Closed Won

AND(
  ISPICKVAL(StageName, "Closed Won"),
  ISBLANK(Amount)
)

Error: "Amount is required to mark an opportunity as Closed Won."

3. Phone format on Contact

AND(
  NOT(ISBLANK(Phone)),
  NOT(REGEX(Phone, "^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$"))
)

Error: "Phone must be a valid format (e.g., 555-555-5555)."

4. Email format on Lead

AND(
  NOT(ISBLANK(Email)),
  NOT(REGEX(Email, "^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$"))
)

Error: "Email address format is invalid."

5. Close Date not in the past on new opportunities

AND(
  ISNEW(),
  CloseDate < TODAY()
)

Error: "Close Date cannot be in the past for new opportunities."

6. Next Step required when advancing past Discovery

AND(
  OR(
    ISPICKVAL(StageName, "Proposal"),
    ISPICKVAL(StageName, "Negotiation"),
    ISPICKVAL(StageName, "Closed Won")
  ),
  ISBLANK(NextStep)
)

Error: "Next Step is required for opportunities in Proposal stage or later."

7. Account required on Contact

ISBLANK(AccountId)

Error: "Every Contact must be linked to an Account."

8. Lead Source required on Lead

ISPICKVAL(LeadSource, "")

Error: "Lead Source is required. Select the channel this lead came from."

9. Prevent backdating Close Date more than 90 days

AND(
  ISCHANGED(CloseDate),
  CloseDate < (TODAY() - 90)
)

Error: "Close Date cannot be more than 90 days in the past. Contact your admin if this is a legitimate backdate."

10. Probability must match stage

AND(
  ISPICKVAL(StageName, "Closed Won"),
  Probability < 100
)

Error: "Probability must be 100% for Closed Won opportunities."

Testing validation rules

Before activating:

  1. Open a test record and try to trigger the rule
  2. Verify the error message appears where expected
  3. Verify the error message is clear
  4. Verify the save succeeds when the condition is met correctly
  5. Test edge cases (blank fields, partial data)

Use a sandbox. Never test validation rules in production.

Common mistakes

1. Rules that fire on every save, not just relevant saves Add context: "AND(ISPICKVAL(StageName, 'Closed Won'), ...)" not just "ISBLANK(CloseDate)".

2. Blocking data migration Validation rules fire during Data Loader imports. Disable them during migration windows, then re-enable.

3. Rules that conflict with each other Two rules that contradict create impossible-to-save records. Audit rules together.

4. No error message on the field Placing all errors at the top of the page makes it hard to find what's wrong. Use "Field" error location when possible.

Want validation rules built for you?

A complete validation rule set — covering all critical objects with clear error messages and tested against your data — takes a senior admin 1-2 weeks.

RevKit's Validation Rule Set delivers 15 rules across your key objects in 48 hours for $249:

  • Audit of current rules (we fix or remove broken ones)
  • 15 new rules covering your critical objects
  • Clear, actionable error messages
  • Testing against your sandbox data
  • Documentation

Get Validation Rules →

Related reading

// Free Diagnostic

Want to see where your org stands?

Get a free diagnostic built by a team with 50+ Salesforce certifications. No email required.

Get Free Health Score

Find out what's broken.

Get a free Salesforce diagnostic matched to your role. No email required.

Ready to build it?

Fixed-price Salesforce builds. No retainers.

Browse all products