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
Service cloud userService cloud user 

Different Apex page message for different error on same VF

Hi,

 

What about if we want to add different error maessage to different output panels in same page.like

 

<apex:outputPanel id="op1">

<apex:pageMessage/>

</apex:outputPanel>

 

<apex:outputPanel id="op2">
<apex:pageMessage/>

</apex:outputPanel>


<apex:outputPanel id="op3">

<apex:pageMessage/>

</apex:outputPanel>


 

How can i specify different message for different apex:message at the same time.??

 

Thanks

Kaushik

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Short answer is you can't.  The apex:pageMessages component displays all messages that have been added to the current page, so if you have multiple of these you will display the same messages multiple times.

 

I've always had to roll my own in this situation.

All Answers

Ispita_NavatarIspita_Navatar

Hi,

           You can use rerender attribute for any action component and show the different messages in different output panel at the same time.

Please refer to the code below  for clarity :-

 <apex:commandbutton action="{!SendValue}" value="SendEmail" rerender="op1,op2,op3"/>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

Service cloud userService cloud user

hi,

 

I got the point , but if throwing an exception then i will directly use ApexPage.addmessgaes() function whch will add that error message to all the <Apex:PageMessage> tag i suppose.

 

What if on some action component i want to specify 2 different error messages in two different <apex:pagemessage> component on click of a single action component.

 

How can i achieve that.?

Please mention if I am not clear.

 

Thanks,

Kaushik

bob_buzzardbob_buzzard

Short answer is you can't.  The apex:pageMessages component displays all messages that have been added to the current page, so if you have multiple of these you will display the same messages multiple times.

 

I've always had to roll my own in this situation.

This was selected as the best answer
Service cloud userService cloud user

Hey thnx bob..

 

May be as a workaround i can use the output label and populate the error messages accordingly.

 

Thanks,

Kaushik Ray

bob_buzzardbob_buzzard

I often end up putting them into an HTML formatted String and using apex:outputText with the escape attribute set to true.

 

Labels would work too though.  You can create Lists of strings for the various places that errors get displayed and iterate those.