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

Testing for Messages



I have VisualForce Page with a controller. I am currently writing a test for the code.

Some of the code is designed to return an Apexpages.Message using the Apexpages.addMessage method.


My question is how I can verify that this method is created, via the Test Method.


Thanks alot,




Get the map of messages prior to invoking the method that will add a message and capture the size.  Then get it again afterwards and verify that the size has increased.  You can also traverse the map and look for your message.


Use ApexPages.getMessages() to retrieve the map.