Thursday 21 November 2013

SFDC : Custom Message on Visualforce

Many times when we creating our visualforce page, we want to our 
custom Information Message, Error or Warning on our visualforce page on satisfying some validation. Salesforce provide few messaging ways which are

1) apex:pageMessage
It is used to display single custom method using Salesforce formatting. we  can decide its severity.

on vF page



severity can also be WARNING, INFO

for more info go to :

2) apex:pageMessages
It is used to display all messages on page, it will display all the custom messages as well as Salesforce generated messages on page.

vf code:
 Controller :

vF page looks something like this:


have you noticed how pageMessages handles all the Error, Warning, Info messages on page, pageMessages is used mostly on vf page.


for more info go to :
3) apex:message :
It is used to display the error message only on a specific field. Allow developers to place specific error for specific field.

vf code :
 
 controller : 

vf page will looks something like this :
as you can see error message is appears for Name field as it is associate only with it, which is mention in <apex:message for="accname"/> where accname is id of inputfield <apex:inputField value="{!account.Name}" id="accname"/>.

for more information go to :
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_message.htm

4) apex:messages :
It is similar to apex:message or you can say it is a composition of all the errors.It will display all the errors but these errors will be displayed as a list with no styling.

Example:

vf code :

controller :


vf page will looks like :

 for more information go to:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_messages.htm



Now do all of them together:

vf code :
controller :

vf page will looks like :

Hope that will solve your confusion among pageMessage, pageMessages, message, messages

Thanks.

1 comment: