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
Robin ShiraRobin Shira 

How to add ApexPages.addmessage in test class

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please enter a valid email'));
return null;

how to add in test class.
Thanks!!!
Biswojeet Ray 11Biswojeet Ray 11

Hello Robin,

 

You can test Like this.

System.assert (ApexPages.getMessages().get(0).getDetail() == 'Please enter a valid email'); 

To know more Please refer this Link - http://salesforce-evershine-knowledge.blogspot.com/2012/07/testing-apexpagesmessage-in-controller.html

I hope it helps you.

Kindly let me know if it helps you and please mark as Best Answer.

Thanks and Regards,
Biswojeet

Biswojeet Ray 11Biswojeet Ray 11

Hi Robin

Please send me the code.

 

Thanks,

Biswojeet Ray 11Biswojeet Ray 11

Hello Robin

 

Please try to create a record according to your "else if" condition. Means which "payment_method" should be 'Credit Card' And related opportunity's Credit_Hold should be True.

Then run the test class.

To check error use 

System.assert (ApexPages.getMessages().get(0).getDetail() == 'Please enter a valid email'); 

 

If you are not getting please send me your full class or full method. Then I will send you the test class code.

 

Thanks,