How to display error messages in the Visualforce page?

To display error messages in the Visualforce page add below tag where you want to display the error message.

Visualforce page:

<apex:pageMessages />

Apex Controller:
 
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
ApexPages.addMessage(myMsg); 

(Or)

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.'));

Cheers!!!

1 comment:

  1. I've never used apex or visual force, can I use this error message at the top of the account page to display a value from an account text field?

    ReplyDelete