Sub topic 7
Error messages and where they appear
This chapter assumes you can write a basic error condition formula and create a rule in Setup under Object Manager. It covers the part users see: the message text and its location on the page.
The two settings
Every rule has an Error Message and an Error Location.
- Error Message is the text shown when the formula returns true. It is limited to 255 characters.
- Error Location is either Top of Page or Field. With Field, you pick one field on the same object.
The formula decides whether the save is blocked. These two settings only control how the failure is reported.
Choosing a location
Use Field when the problem belongs to one field. The user sees the message beside the field they must fix, and the field is highlighted. Use Top of Page when the rule compares several fields or no single field is at fault.
Two practical points:
- The field you choose must be visible on the page layout. If it is not, the user may not see the message where you expect it, so check the layout used by each profile or record type.
- You can pick only a field on the same object. A rule that reads
Account.Industryfrom an Opportunity still reports on an Opportunity field or at the top of the page.
Writing messages users can act on
A good message names the problem and the fix. Compare these:
| Weak message | Better message |
|---|---|
| Invalid amount. | Enter an Amount greater than 0 before moving to Negotiation/Review. |
| Error in postal code. | Enter a 5-digit ZIP code or ZIP+4, such as 94105 or 94105-1234. |
| Not allowed. | Only users with the Can Edit Opportunity Amount permission can change Amount. Ask your administrator. |
Keep these habits:
- State the condition in the user's words, not field API names.
- Say what to do next.
- Keep it short. Do not repeat the field label if the message appears next to that field.
- Write each message so it still makes sense at the top of the page, in case the location changes later.
Example
Here is the rule from the previous chapter with its settings filled in.
Rule Name: Amount_Required_In_Negotiation
Error Condition Formula:
AND(
ISPICKVAL(StageName, "Negotiation/Review"),
OR(ISBLANK(Amount), Amount <= 0)
)
Error Message: Enter an Amount greater than 0 before moving to Negotiation/Review.
Error Location: AmountThe problem is with Amount, so the message is attached to Amount.
Other places the message appears
Messages are not limited to the record page. Data loads, API calls, and Apex DML return the same text with the status code FIELD_CUSTOM_VALIDATION_EXCEPTION. A data loader operator will read your message in an error file with no layout around it. Another reason to make it self-explanatory.
Exercise
A rule compares CloseDate and a custom field StartDate_c and blocks saves when CloseDate is earlier. Which error location suits it, and what should the message say?
Show answer
Either location can work. Top of Page fits because two fields are involved. Field also works if you attach it to CloseDate, the field the user most likely needs to change. A suitable message: "Close Date cannot be earlier than the Start Date. Choose a Close Date on or after the Start Date."