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
Jay_HunterJay_Hunter 

Can't get <apex:pagemessages /> to render a message.

I'm struggling with being able to show a basic success message to the user using the standard <apex:pagemessages /> component.  I've got it on the page, but it never shows a message.  Here's the page:

 

<apex:pageblock > <apex:pageblockSection > <h1>Page Messages:</h1> <apex:pageMessages /> </apex:pageblockSection>

 Nothing unusual there, right?

 

Here's the controller method that generates the message.  Basically I've got a list with checkboxes, and the user selects some, clicks a button, and then records are inserted based on the selections.  When that happens, I'd like to let the user know the insert was successful.

 

 

if (billTos.size() > 0) { try{ insert billTos; // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Bill-To Sites successfully created')); } catch (DMLException e){ // show the messages to the user ApexPages.addMessages(e); } } else { // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No Sites Selected')); }

 

My records are being successfully inserted, so it should be hitting the success message.  But it's all silent on the page -- nary a peep.  What the heck am I doing wrong?  This seems simple!!

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

Having the full code makes for easier debugging :smileyvery-happy:

 

Anyway, I think you're getting close. Try this:

 

...

<apex:pageblock id="theBlock" > <apex:pageMessages/> <apex:pageBlockButtons > <apex:commandButton value="Save Selected Bill To Sites" action="{!processSelected}" rerender="theBlock,table"/>

...

All Answers

CaptainObviousCaptainObvious

Try returning null after your else statement:

} else { // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No Sites Selected')); } return null;

This should re-render your pagemessages.

EnthEnth
Presumably your VF page also has apex:form tag outside the pageBlock (and is properly terminated, the code you pasted is incomplete) ??? 
Jay_HunterJay_Hunter

Thanks for the suggestion captain.  Love that screen name BTW!

 

Unfortunatley, I already have the return null line in there.  Here's the full method:

 

public PageReference processSelected(){ //We create a new list of Accounts that we be populated only with Accounts // if they are selected List<Account> selectedAccounts = new List<Account>(); //We will cycle through our list of aAccounts and will check to see if the //selected property is set to true, if it is we add the Account to the //selectedAccounts list. for(aAccount aAcc : getAccounts()){ if(aAcc.selected == true){ selectedAccounts.add(aAcc.acc); } } //Now we have our list of selected accounts and can perform any type of //logic we want, sending emails, updating a field on the account, etc //System.debug('These are the selected Contacts...'); List <Bill_To_Sites__c> billTos = new List<Bill_To_Sites__c>(); for(Account acc : selectedAccounts){ Bill_To_Sites__c b = new Bill_To_Sites__c(); b.Account__c = acc.Id; b.Opportunity_Account__c = ApexPages.currentPage().getparameters().get('id'); billTos.add(b); } if (billTos.size() > 0) { try{ insert billTos; // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Bill-To Sites successfully created')); } catch (DMLException e){ // show the messages to the user ApexPages.addMessages(e); } } else { // set the message for the user ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No Sites Selected')); } return null; }

 

 

 

Jay_HunterJay_Hunter

Enth,

I think the page is structured as you suggest.  Here's the full page code:

 

<apex:form > <apex:pageblock > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save Selected Bill To Sites" action="{!processSelected}" rerender="table"/> </apex:pageBlockButtons> <apex:pageblockSection > <h1>Potential Bill-To Accounts for this Opportunity</h1> </apex:pageblockSection> <apex:pageblockSection showHeader="true" title="Potential Bill-To Accounts" id="list" columns="1"> <apex:pageblocktable value="{!accounts}" var="a" id="table"> <apex:column > <apex:inputCheckbox value="{!a.selected}"/> </apex:column> <apex:column value="{!a.acc.Name}"/> <apex:column value="{!a.acc.Site_Number__c}"/> <apex:column value="{!a.acc.BillingStreet}"/> <apex:column value="{!a.acc.BillingCity}"/> <apex:column value="{!a.acc.BillingState}"/> </apex:pageblocktable> </apex:pageblockSection> </apex:pageblock> </apex:form> </apex:page>

 

 

 

EnthEnth
It *shouldn't* matter, but try putting the pageMessages after the pageBlockButtons.
Message Edited by Enth on 29-03-2010 11:25 PM
Jay_HunterJay_Hunter
Thanks for the additional suggestion Enth.  I tried it just now  but unfortunately, still no @^^$@! page messages. 
CaptainObviousCaptainObvious

Having the full code makes for easier debugging :smileyvery-happy:

 

Anyway, I think you're getting close. Try this:

 

...

<apex:pageblock id="theBlock" > <apex:pageMessages/> <apex:pageBlockButtons > <apex:commandButton value="Save Selected Bill To Sites" action="{!processSelected}" rerender="theBlock,table"/>

...

This was selected as the best answer
Shailesh DeshpandeShailesh Deshpande

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=27292#M27292

 

 

 

go through the reply by spd.....it is not using page:messages.....but it shows howto display a message without using it...

 

 

i hope this helps...

Jay_HunterJay_Hunter
Captain Obvious, you are a master of your domain (the obvious).  Thanks, that worked!!:smileyvery-happy:
Master_KeyMaster_Key
This helped me a lot. Thanks a ton. 
David Roberts 4David Roberts 4
Thanks Captain Obvious. Although you've no doubt been promoted by now. Admiral? Certainly admirable!