Adding Error Message in the Visualforce page through Apex controller

Syntax : <apex:pageMessages ></apex:pageMessages>

Apex Controller:

public class ErrorMsgController {
public void DisplayError(){
Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, ‘Required fields are missing. ‘)); //FATAL, WARNING, INFO, CONFIRM

VF Page:

<apex:page sidebar=”false” showHeader=”false” controller=”ErrorMsgController”>
<apex:form >
<apex:pageMessages ></apex:pageMessages>
<apex:commandButton value=”Click” action=”{!DisplayError}”/>


Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *