Cert++
Close

Validation rules versus flow custom errors for blocking saves

Key Takeaway

Validation rules block bad saves on new and updated records. To stop a deletion without code, use a Custom Error element in a record-triggered flow that runs before deletion.

Validation rules and the Custom Error element in Flow are two no-code ways to stop a bad change from being saved and tell the user why. A validation rule is a formula on an object that blocks the save when it returns True. A Custom Error is an element in a record-triggered flow that undoes the change that started the flow and shows a message you write. To pick the right tool, look at what kind of change you need to stop and where in the save each check runs.

Validation rules

A validation rule holds a formula or expression that checks one or more fields and returns True or False. A result of True means the data is invalid, so Salesforce shows the rule's error message and does not save the record. The user then fixes the data and clicks Save again.

Validation rules apply to new and updated records, even when the fields they reference aren't on the page layout or in the API call. Validation rules don't apply when users create records with Quick Create, which leaves a gap in validation rule coverage.

You choose where the message appears by setting the error location to "Top of Page" or to a specific "Field". If that field is later deleted, made read only, or not visible on the page layout, Salesforce automatically moves the error to Top of Page. Include the field label in the message so users can still tell which field failed.

Sam edits an opportunity and sets the Close Date to a day last week. A validation rule with the formula CloseDate < TODAY() has its error location set to the Close Date field. The formula returns True, so Salesforce shows the rule's message next to Close Date and doesn't save the opportunity. Sam picks a date next month and clicks Save again, and the record saves.

Platform Administrator II Study Guide

Checklist progress

0/290Learned

Given a complex scenario, determine the solution using the best tool or combination of tools to solve a business problem

0/14

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other Platform Administrator II studiers.