Validation rules for conditional enforcement, existing data and bypass
Key Takeaway
A new validation rule also checks old records the next time anyone edits them. Add ISNEW() and ISCHANGED() conditions so the rule fires only when a record is new or the field it checks changed. Use a custom permission to let chosen users bypass a rule.
A validation rule is a formula that Salesforce checks when a user saves a record. If the formula returns TRUE, Salesforce blocks the save and shows an error message. Admins add functions such as ISNEW(), ISCHANGED() and PRIORVALUE() so that a rule fires only in the right situations and older records stay editable after the rule goes live. A custom permission lets chosen users bypass a rule.
How a validation rule works
A validation rule holds two things: a formula and an error message. The formula checks one or more fields and returns TRUE or FALSE. When a user saves a record and the formula returns TRUE, Salesforce blocks the save and shows the error message.
Write the formula to describe the bad data you want to stop, not what good data looks like. The condition alone is enough, so you don't need to wrap it in IF(condition, TRUE, FALSE). For example, this formula checks the Account Number:
AND(NOT(ISBLANK(AccountNumber)), LEN(AccountNumber) != 8)The formula returns TRUE when the Account Number is filled in but is not exactly eight characters long, so Salesforce blocks that save. A blank Account Number makes the formula return FALSE, so Salesforce still allows it.
When one rule fails, Salesforce keeps checking the other rules and shows all the error messages at once.