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
Linda 98Linda 98 

Display error message on Vf page

I am having a VF page which has input text and i made them required by wrapping in outputlabel.
Like this
 
<apex:pageBlockSectionItem >
               <apex:outputLabel value="Contact Email"/>
               <apex:outputPanel layout="block" styleClass="requiredInput">
               <apex:outputPanel layout="block" styleClass="requiredBlock"/>
               <apex:inputtext label="Email" value="{!contactemail}"/>
               </apex:outputPanel>
            </apex:pageBlockSectionItem>

I would like to display error message when email field is not filled.

I am giving <apex:pagemessages /> in Vf page and below add message in apex class before i upsert contact.

if( Email == null || email== '' ){
    ApexPages.addMessage( new ApexPages.Message( ApexPages.Severity.ERROR, 'Please enter Email'));
   return null;           
}
Still it doesnt work.Please guide me where am i going wrong.
 
Akash_CRMAkash_CRM
Hi Linda,

Looks like you are using the wrong variable name in the check of Controller, it should instead be:

if( contactemail == null || contactemail == '' ){
    ApexPages.addMessage( new ApexPages.Message( ApexPages.Severity.ERROR, 'Please enter Email'));
   return null;           
}

Regards,
Akash.
Sri549Sri549
Are you able to see the error message now ? When the email field value is blank.

Thanks,
Srinivas Gupta
GauravGargGauravGarg

Hi Linda,

Can you please post the VF page here. 

Thanks,

Gaurav
Email: gauravgarg.nmims@gmail.com