function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NipuWNipuW 

Question on <apex:pageMessages/>

We can see the error messages once we add the <apex:pageMessages/> tag in to the page. This shows error messages at component level. From where it takes these individual messages? Is it taking it from the field configurations?
Best Answer chosen by NipuW
ANUTEJANUTEJ (Salesforce Developers) 
So if there are any errors in the page that may occur the system directly throws these messages, but in case if you want to make it more user friendly to show a certain specific message then you can use the above-mentioned way.

Hope I was able to address your question.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Nipu,

You can give custom messages by using ApexPages.addmessage(' message goes here ') and the added message would be going to the place where the tag is present

Please view the below developer forum thread for example:

>> https://developer.salesforce.com/forums/?id=906F0000000BG2lIAG

In case if this came in handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
NipuWNipuW
Thanks Anutej for the reply. It really helped me a lot. My question is where it get those default messges to display. For an example the following code include a <pagemessge> tag which will apply to all the components in the page. It will display appropriate messge on each and every component seperatly. From where it generate/get those messges?
<apex:page standardController="Opportunity" recordSetVar="opportunities"
    tabStyle="Opportunity" sidebar="false">
    <p>Enter an alphabetic character for the "Close Date," 
       then click Save to see what happens.</p>
    <apex:form >
        <apex:pageBlock >
        <apex:pageMessages />
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!opportunities}" var="opp">
                <apex:column value="{!opp.name}"/>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.closeDate}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
ANUTEJANUTEJ (Salesforce Developers) 
So if there are any errors in the page that may occur the system directly throws these messages, but in case if you want to make it more user friendly to show a certain specific message then you can use the above-mentioned way.

Hope I was able to address your question.
This was selected as the best answer
NipuWNipuW
Yes Anu. Thanks a lot :)
ANUTEJANUTEJ (Salesforce Developers) 
Glad I was able to answer your question :)