While converting a utility class from V26 to V31, my VF testmethods started breaking.

Problem was traced down to how ApexPages.addMessage() behavior varies if the i+1st message has the same summary as the ith message, even if the detail argument is different between i+1st and ith message.

If the summary values are the same, the i+1st message won't get added to the page messages.

Here is the code that proves this:

private static void testAddVFMsg() {    
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'MsgSummary','00detail'));

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'MsgSummary','01detail'));
     // passes at V28 and earlier, fails at V29+


Obviously I can work around this by using different values for the summary argument in the ApexPages.Message constructor or reworking my testmethod expectations.

But - seems to me that if you call addMessage(..), the resulting getMessages() should include the message you added.

So - the question is:

  • Bug? or
  • Documentation needs enhancing?
  • ever raised this with salesforce support? Oct 1, 2014 at 8:58
  • no, not yet - was waiting to see if others had already noticed this and had initiated action w/ SF Support
    – cropredy
    Oct 1, 2014 at 17:57

1 Answer 1


I have personally run into several problems using apex page messages - everything from messages not showing up, to ui breaking on different browsers and everything in between.

personally I prefer to approach error handling with a simple Boolean and String. In the case of an error you simply set the Boolean to true (set to false in constructor) and write an error message in the string.

If you are wishing to view this on a VF page you can simply add an outputPanel

<apex:outputPanel id="errorArea"> 
<apex:outputPanel rendered="{!error}">  
<apex:outputText value="{!errorMsg}" /> 

Where error is the Boolean and errorMsg is the String. At the beginning of each class simply set the boolean to false and to true again if another error occurs.

This way you have complete control over the message handling, the level of detailing in your debug as well as presentation on the VF page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .