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
GobbledigookGobbledigook 

Apex:messages not working

Ok, so for some reason my Messages aren't being displayed, even though I (Seem to) have everything all set up.

 

VF page setting up the messages:

 

 

<apex:messages rendered="true" style="color:Red;"/>

 

 

Apex Code calling and creating a message:

 

 

 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, 'Call Attendees: ' + CallAttendeeSum + 'uploaded'));
            

 

 

I get no compile errors, no errors of any kind at all, the message just does not display. What gives?

Best Answer chosen by Admin (Salesforce Developers) 
GobbledigookGobbledigook

Thank you for your replies, but for some reason that didn't work either.  I found a workaround using <apex:outputText> and resetting the string to the error message and calling a rerender, but for some reason apex:messages still wouldn't work. 

Thank you for your replies!

 

(Oh, and just incase someone else may need this workaround):

 

In Apex Class:

 

String msg {get;set;}

public StandardConstructor (ApexPages.StandardController){ msg = null; }

// Elsewhere in the class, where you would want to set the message.

msg = Display Message; 

 

 

And Visualforce:

 

Put anywhere on your VF Page: 

<apex:outputText rendered="true" style="color:#ff0000;" value="{!msg}" id="msg"/>

And just set a re-render on whatever needs to trigger the message.

 

 

This actually has the added benefit of being able to render messages ANYWHERE on your Visualforce page, other than being limited to the standard error message.

 

Thanks for your help though all!

 

All Answers

sherodsherod

Have you tried  <apex:PageMessages /> ?

Imran MohammedImran Mohammed

If you are invoking an action from VF page, then you should rerender the apex:pageMessages tag using the id.

ex: <apex:pageMessages id='msg' style="your code here"/>

If the apex code you specified is declared in the controller constructor, it should display pageMessage when the VF page gets loaded.

GobbledigookGobbledigook

Thank you for your replies, but for some reason that didn't work either.  I found a workaround using <apex:outputText> and resetting the string to the error message and calling a rerender, but for some reason apex:messages still wouldn't work. 

Thank you for your replies!

 

(Oh, and just incase someone else may need this workaround):

 

In Apex Class:

 

String msg {get;set;}

public StandardConstructor (ApexPages.StandardController){ msg = null; }

// Elsewhere in the class, where you would want to set the message.

msg = Display Message; 

 

 

And Visualforce:

 

Put anywhere on your VF Page: 

<apex:outputText rendered="true" style="color:#ff0000;" value="{!msg}" id="msg"/>

And just set a re-render on whatever needs to trigger the message.

 

 

This actually has the added benefit of being able to render messages ANYWHERE on your Visualforce page, other than being limited to the standard error message.

 

Thanks for your help though all!

 

This was selected as the best answer