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
Anna Proviz 11Anna Proviz 11 

apex:pageMessages clear()

Hello,

I have an apex:pageMessages tag on my VF Page .
On the controller side I doing 
ApexPages.getMessages().clear();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ErrorMsg));
But for some reason the clear() is not working .
I see the collection of old errors with a new one on the Page ...

Somebody please help ...
 
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Anna Proviz 11:

 In fact, ApexPages.getMessages().clear(); should clear all the messages in the  collection. If you can share the code, it will help to see how you implemented that in your code, which helps in resolving the issue .

Thanks,
Balaji
joe1.3898212780713167E12joe1.3898212780713167E12
The line of code "ApexPages.getMessages().clear();" simply clears the lsit returned by getMessages(), not the actual page messages themselves.  There is no clearMessages() method at this time.  Although it hasn't helped me yet, you can check out https://developer.salesforce.com/forums/ForumsMain?id=906F00000008xr1IAA for a more thorough dicsussion.