Skip to main content

Code reviews rule: Missing messages in Visualforce page

Written by David Martin
Updated today

Missing messages in Visualforce page

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">
<!-- No message component - errors will be invisible -->
<apex:form>
<apex:inputField value="{!account.Name}"/>
<apex:commandButton value="Save" action="{!save}"/>
</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 with standard Salesforce styling

  2. <apex:messages/> - Displays all messages in a simple list format

  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.

Note: The rule also checks custom components (c:ComponentName), included pages (apex:include), and composition templates (apex:composition). Adding a message tag in any of these will also resolve the violation.

When should I disable this rule?

You may want to dismiss this issue if:

  • The page uses a custom JavaScript-based notification system (such as toast messages) instead of standard Visualforce message components

  • Messages are displayed through a managed package component, as the rule only analyzes custom components local to your project

Resources

Did this answer your question?