Experience Salesforce

Apex Page Message in Visualforce

What You’ll Learn

  • Display Message On 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 Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
Rakshabandhan Sale