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
pjcocopjcoco 

Check for Error Messages in Visualforce Page

Dear Developers,

 

Is it possible to check if the page has error messages? So I can stop rendering part of the page when it has error messages?

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

You could use a custom controller or extension method that returns the value of ApexPages.hasMessages() , then use it in a rendered=... attribute to supress rendering.

All Answers

aballardaballard

You could use a custom controller or extension method that returns the value of ApexPages.hasMessages() , then use it in a rendered=... attribute to supress rendering.

This was selected as the best answer
Griffin scroogeGriffin scrooge
<apex:page>
<apex:form>
    <apex:pageblocktitle="New recruit"/>
    <apex:pageblocksectioncolumn="1">
   <apex:pageBlockSectionItem>
       <apex:outputlabel value="First name"/>
       <apex:inputtext/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem>
            <apex:outputLabel value="lastname"/>
           <apex:inputText />
        <apex:pageBlockSectionItem/>
        <apex:pageBlockSectionItem>
       <apex:outputLabel value="Salary"/>
            <apex:inputtext/>    
        <apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem/>
      <apex:outputlabel value="Experience"/>
            <apex:inputtext/>
        <apex:pageBlockSectionItem/>
    <apex:pageblocksection/>
    <apex:form/>
    <apex:page/>