Skip to main content

Code reviews rule: Visualforce Page Without Messages

Written by David Martin
Updated this week

Visualforce Page Without Messages

Why is this an issue?

Visualforce pages that lack message components (<apex:pageMessages>, <apex:messages>, or <apex:message>) cannot display error messages, validation errors, or informational messages to users. When controller actions add messages to the page context, they will be silently ignored if no message component exists to render them.

This can lead to:

  • Users being unaware of errors or validation failures

  • Silent failures that are difficult to debug

  • Poor user experience when operations fail without feedback

Examples

Example of incorrect code:

<apex:page controller="MyController">
<apex:form>
<apex:inputField value="{!account.Name}"/>
<apex:commandButton value="Save" action="{!save}"/>
<!-- No message component - errors will be invisible -->
</apex:form>
</apex:page>

Example of correct code:

<apex:page controller="MyController">
<apex:pageMessages/>
<apex:form>
<apex:inputField value="{!account.Name}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>

How can I fix violations?

Add one of the following message components to your page:

  1. <apex:pageMessages/> - Displays all messages for all components

  2. <apex:messages/> - Displays messages not associated with specific components

  3. <apex:message for="componentId"/> - Displays messages for a specific component

Place the message component prominently on the page, typically near the top or near the form it relates to.

When should I disable this rule?

You may want to dismiss this issue if:

  • The page is display-only with no user interactions that could generate messages

  • You are using a custom JavaScript-based notification system

  • Messages are handled by an included component or template

Resources

Did this answer your question?