15

Apex Page Message in Visualforce

Display Message On Visualforce

Whenever we want to display a message on a page, we can use a <apex:pageMessage> tag. Here below is the example code:

<apex:page controller="MyController">
     <apex:pageMessage severity="Error" summary="First
Error message on page" strength="1"></apex:pageMessage>
     <apex:pageMessage severity="Error" detail="Second Error message on page" strength="2"></apex:pageMessage>
     <apex:pageMessages ></apex:pageMessages>
</apex:page>

Here is the example of controller which can be defined to add message to the page:

public class theController {
      public theController(){
             ApexPages.addmessage(new ApexPages.message( ApexPages.severity.Error, 'First Error Message added from apex'));
             ApexPages.addmessage(new ApexPages.message( ApexPages.severity.Error, 'Second Error Message added from apex'));
     }
}

salesforce-developer
Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

ServiceNow Stripe