Automation
Validation rules
Write formula-based rules that block a record save when data does not meet your process requirements — with a custom error message shown to the user.
What validation rules do
A validation rule evaluates a formula expression every time a record is saved. When the formula returns True, the save is blocked and your configured error message is shown. When it returns false, the save proceeds normally.
Think of the formula as describing the error condition: write it so it evaluates to true when something is wrong. Validation rules fire on both record creates and updates. They run synchronously as part of the save — if any active rule returns true, no changes are committed.
Where to create rules
Go to Setup () → Objects, open the object you want to validate, and select its Validations tab. Create a new rule, give it a name and optional description, write the formula, and write the error message.
New rules are active by default. Untick Active while you are still working on a rule — inactive rules are ignored entirely during saves.
Formula semantics
The validation formula must return a Boolean value. The logic is:
- true — rule fires; save is blocked; error message is shown to the user.
- false — rule passes; save continues.
An empty field does not fire a rule on its own: a blank compared with anything is false, so Amount < 100 stays false while Amount is empty. To require a value, say so: IsBlank(Amount). The formula is checked when you save the rule — Validate Formula runs the same check — and every value in it must be the right kind for what it is used in (see Fields → Formula syntax and supported functions for the rules about kinds of values, dates and blanks).
Write the formula to describe what is invalid:
// Block if CloseDate is in the past (fires when CloseDate < today)
CloseDate < TODAY()
// Block a "Closed Won" stage if Amount is blank
AND(Stage = "Closed Won", IsBlank(Amount))
// Block if discount exceeds 30% without manager approval
AND(Discount > 30, NOT(ManagerApproved))
// Block a name shorter than 3 characters
Length(Trim(Name)) < 3
// Block reopening a won deal (old vs new value)
AND(OldRecord.Stage = "Closed Won", Stage != "Closed Won")
// Block changing the amount of a won deal
AND(IsChanged(Amount), Stage = "Closed Won")
// Block creating a deal that is already won
AND(IsNew(), Stage = "Closed Won")Field references
Reference a field directly by its API Name — for example, Stage, Amount, CloseDate. To traverse a lookup relationship, use dot notation with the lookup field's API name: AccountId.Industry reads the Industry field from the related Account record.
All field values reflect the record's state at the moment the save fires — including any changes made in the current save operation. Relationship paths work up to three levels deep, and formula fields referenced by a rule are calculated first, so the rule sees their current values.
Old and new values
A rule can also see the record as it was before the save: OldRecord.Stage is the Stage before the save (in the Fields picker, under Old Record). IsChanged(Amount) is True when the save changes Amount — compared as = compares, so emptying a field that was never filled is not a change — and IsNew() is True while the record is being created. On create there is no “before”: the OldRecord fields are blank and IsChanged is False. Only the record's own fields have an old value; IsChanged(AccountId.Name) is refused. Every way a record is saved runs the rules with its old values: the record page, a list's inline edit, imports, the API, flows and lead conversion.
Formula functions reference
Validation rules use the same functions as formula fields (see Fields): Logic: IF, AND, OR, NOT, FirstNotBlank, IsBlank, IsNull. Text: Text, Concat, Lower, Upper, Trim, Length, Left, Right, Substring, Contains, Find, StartsWith, EndsWith, Replace, UrlEncode. Numbers: Number, Abs, Round, Floor, Ceil, Min, Max, Negate. Dates: Today, Now, Date, Year, Month, Day, AddDays, AddHours, AddMonths, AddYears, DaysBetween, Hour, Minute. Also Case, Mod, Power, MatchesPattern, ContainsPattern, Includes, and — in validation rules and flows only — IsChanged and IsNew.
If a formula field the rule refers to can't be calculated (for example, it divides by zero), it counts as empty for the rule, so a broken formula never blocks a save on its own.
Error messages
The error message is shown to the user when the rule blocks a save. Write messages that tell the user exactly what to fix, not just that something failed.
- Good: "Close Date must be today or in the future."
- Good: "Amount is required when Stage is Closed Won."
- Avoid: "Validation error." — not actionable.
Messages support plain text only. When multiple rules fail simultaneously, all of their messages are shown together on the form.
Multiple rules on the same object
An object can have any number of active validation rules. On every save, all active rules are evaluated — there is no short-circuit. If three rules fire on the same save, the user sees all three error messages at once so they can address everything in a single correction rather than fixing one at a time.
Activating and deactivating rules
Toggle a rule active or inactive at any time from the rule's detail page. Deactivating does not delete the rule or its configuration. Common uses for deactivation:
- Temporarily suspend a rule during a data migration or bulk import where records may not yet have all required fields filled.
- Disable a rule while reconfiguring it, so a half-updated formula does not block saves.
- Archive a rule you may need again without deleting it.
Interaction with required fields
Field-level Required settings and validation rules are independent layers. A field marked Required is enforced by the UI form before the save is even attempted. Validation rules evaluate server-side after the form submits. Use field-level Required for straightforward presence requirements, and validation rules for conditional or cross-field logic — for example, "Amount is required only when Stage is Closed Won."