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
DevelopementDevelopement 

VF page is not showing the error

Hey,

I created this visualforce page. Page works fine.
Issue : Some fields are required on the page layout. It shows as Red mark. but when i hit save it doesn't show me the error on the field like below:

User-added image

I want when i hit save it should show error like above on the fields that are required on the page layout. Here is the VF page:
 
<apex:page standardController="Opp" extensions="oppsController">
    <apex:sectionHeader title="Opp Edit" subtitle="{!Opp.OppNumber}"/>
    <apex:form id="frmId">
   

        <apex:pageBlock id="pb" title="Opp Edit" mode="edit">
  <apex:messages ></apex:messages>
            <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}" rerender="theForm"/>
 
            <apex:commandButton value="Cancel" action="{!Cancel}" rerender="theForm"/>
 
         </apex:pageBlockButtons> 


            <apex:pageBlockSection id="pb1" title="Opp" columns="2">
                <apex:inputField value="{!Opportunity.Account_name__c}" required="True"/>
                <apex:inputField value="{!Opportunity.Active_Status__c}" required="True"/>
                <apex:inputField value="{!Opportunity.OppNumber}" required="True"/>
                 <apex:inputField value="{!Opportunity.RecordTypeId}" required="True"/>
                
            </apex:pageBlockSection>


            <apex:pageBlockSection id="pb2" title="Details" columns="2">
              <apex:messages ></apex:messages>
                <apex:inputField value="{!Opportunity.Opp_Country__c}" required="true"/>
                <apex:inputField value="{!Opportunity.Region__c}" required="True"/>
                <apex:inputField value="{!Opportunity.Sub_Region__c}" required="True"/>
            </apex:pageBlockSection>
         
        </apex:pageBlock>
    </apex:form>
</apex:page>

Does anyone know how to fix it?

Thanks.
 
Best Answer chosen by Developement
Deepak GulianDeepak Gulian
<apex:pageBlockButtons >
         <apex:commandButton value="Save" action="{!save}" />
         <apex:commandButton value="Cancel" action="{!Cancel}" />
</apex:pageBlockButtons>
Replace button section with this!
 

All Answers

Deepak GulianDeepak Gulian
<apex:pageBlockButtons >
         <apex:commandButton value="Save" action="{!save}" />
         <apex:commandButton value="Cancel" action="{!Cancel}" />
</apex:pageBlockButtons>
Replace button section with this!
 
This was selected as the best answer
DevelopementDevelopement
Thanks it worked :)
But what about validation error message. when i hit save error comes in this form
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION

 
R Z KhanR Z Khan
Use apex:pagemessages instead of apex:messages

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageMessages.htm
Deepak GulianDeepak Gulian
1. Add the <apex:pageMessages/> tag to your page. (This is the container that displays any error messages if present)

2. Surround your DML call with try {} catch(DMLException e) {} (When you catch the exception you won't get redirected to the error pages, but salesforce will automatically create a "PageMessage" for the validation failure.
DevelopementDevelopement
Thanks I will try this out.

@Deepak: could you please explain why rerender="theForm" was not working? Why have to remove that in order to make it work?
 
<apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}" rerender="theForm"/>
 
            <apex:commandButton value="Cancel" action="{!Cancel}" rerender="theForm"/>
 
         </apex:pageBlockButtons>

 
Deepak GulianDeepak Gulian
There was no Id in VF page named "theForm"
R Z KhanR Z Khan
replace it with rerender="frmId"