Activity Forums Salesforce® Discussions What is the difference between apex:pageMessages, apex:pageMessage, apex:Message?

  • madhulika shah

    Member
    July 31, 2018 at 1:29 pm

    Hi Shradha,

    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.

  • shariq

    Member
    September 18, 2018 at 11:08 pm

    Hi,

    To add Example -

    <apex:page controller="TestMessageController">
    <apex:pageMessages />
    <apex:pageMessage summary="This is apex:message" severity="info" strength="2"/>
    <apex:messages />
    <apex:form >
    <apex:outputLabel value="Test String" /><apex:inputField value="{!test.Name}" id="test"/>
    <br/><apex:message for="test"/>
    </apex:form>
    </apex:page>

    public class TestMessageController{
    public Account test{get;set;}
    public TestMessageController(){
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This is apex:pageMessages'));
    test = new Account();
    test.Id.addError('Correct');
    test.Name.addError('Wrong');
    }
    }

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos