+ Start a Discussion
Harshit`AgarwalHarshit`Agarwal 

Difference b/w pageMessages, pageMessage,Message and Messages in apex?

Hi,
I am confused in what cases should we use apex:pageMessages, apex:pageMessage, apex:Message and apex:Messages? 

Thanks.
Harshit
Shubham NandwanaShubham Nandwana
Hi,
The brief explanation of all is below.

apex:PageMessages:
This component displays all messages that were generated for all components on the current page, presented using the salesforce styling. This will display both salesforce generated messages as well as custom messages added to the ApexPages class 

apex:PageMessage:
Apex:PageMessage is a component that adds a single message on the page. This is used to display a custom message using the salesforce formatting

apex:Message:
apex:Message is used to display an error on only a specific field. It is used to allow developers to place field-specific errors in a specific location.

apex:Messages:
apex:Messages is similar to apex:Message but it displays all errors

Hope it helps.

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
Akshay_DhimanAkshay_Dhiman
Hi Harshit,

apex:PageMessages is a containing component where any messages that have been added to the page will appear.

 

apex:pageMessage is a component that adds a single message to the page.

 

apex:message allows you to associate a message with a component

 

I've not used apex:messages - I can't see how it particularly differs from apex:pagemessages

 

ApexPages.Message is the class that is used to model a message.  A message isn't associated with a page until it is added via the ApexPages class.

 

ApexPages is a class that allows you to access the current page (through ApexPages.CurrentPage()) and manages messages for the current page.

 

I'd start off by adding an apex:pageMessages component to the top of your page and then add some messages in programmatically via the ApexPages methods - that should help clarify things.


Thanks 
Akshay