« Explore the Different Messaging Options in VisualForce (Part 2) | Main | Use SOQL's OFFSET Clause to Paginate your Visualforce Pages »

Explore Different Messaging Options in VisualForce (Part 1)

VisualForce offers several options when it comes messages such as a warning of an error. Today, I'm going to explain the key differences between the messaging options in VisualForce:

  • apex: pageMessage is used to display a single custom message using the Salesforce formatting. With this one, you have the option to control and specify the "Severity" (the displaying of the message box) and the "Strength" (size of the box). Check out the below code for an example:

    <apex:pageMessage summary="This is a pageMessage" severity="error" strength="1"/>
  • Another option is to use apex: pageMessages; which is used to concurrently display the custom messages entered by the developer and those generated by Salesforce. See the example in the code below and how it renders:
 <apex:page controller= "TestMessageController">
  <apex:pageMessages />
public class TestMessageController{
    public TestMessageController(){
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This is apex:pageMessages'));
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This is apex:pageMessages still'));
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This is apex:pageMessages info'));
         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This is apex:pageMessages warning'));

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

You made one mistake. In last line you should use "ApexPages.Severity.WARNING", therefore screenshot will be different too.
Despite that, good post!

April 27, 2013 | Unregistered CommenterƁukasz Skrodzki

Thanks for the feedback! I will look into this.

May 1, 2013 | Registered Commentersfgeneral

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
All HTML will be escaped. Hyperlinks will be created for URLs automatically.