You need to sign in to do that
Don't have an account?
sekhar 131
How to Display the date Field fronted error message in visualforce
How to Display the date Field fronted error message in visualforce
Date Field is select the future date throw error message
Date Field is select the future date throw error message
In order to show error on your VfPage, you need to use the <apex:pageMessages> in your VfPage.
So firstly you have created a validation rule which will be having the condition like:
Student_Date_Of_Birth > TODAY()
(I have taken a custom object named Student__c)
Then you have to make a VfPage as:
<apex:page standardController="Student__c" extensions="StudentExt" >
<apex:pageMessages id="errormsg" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!saveStudent}" reRender="errormsg"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" title="Information">
<apex:inputField value="{!Student__c.First_Name__c}"/>
<apex:inputField value="{!Student__c.Last_Name__c}"/>
<apex:inputField value="{!Student__c.Date_of_Birth__c}"/>
<apex:inputField value="{!Student__c.Address__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
And the controller will be like:
public class StudentExt {
public Student__c student{get;set;}
public StudentExt(ApexPages.StandardController controller) {
student = (Opportunity)controller.getRecord();
}
public Pagereference saveStudent() {
try {
Upsert student;
return new Pagereference('/' + student.Id);
}
catch(DMLException de) {
Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, de.getDmlMessage(0)));
return NULL;
}
catch(Exception e) {
Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, e.getMessage()));
return NULL;
}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
Please try Use this code
Please mark it best answer if it helps you.
Thanks!!!
Saravanan Rajarajan
In order to show error on your VfPage, you need to use the <apex:pageMessages> in your VfPage.
So firstly you have created a validation rule which will be having the condition like:
Student_Date_Of_Birth > TODAY()
(I have taken a custom object named Student__c)
Then you have to make a VfPage as:
<apex:page standardController="Student__c" extensions="StudentExt" >
<apex:pageMessages id="errormsg" />
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!saveStudent}" reRender="errormsg"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" title="Information">
<apex:inputField value="{!Student__c.First_Name__c}"/>
<apex:inputField value="{!Student__c.Last_Name__c}"/>
<apex:inputField value="{!Student__c.Date_of_Birth__c}"/>
<apex:inputField value="{!Student__c.Address__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
And the controller will be like:
public class StudentExt {
public Student__c student{get;set;}
public StudentExt(ApexPages.StandardController controller) {
student = (Opportunity)controller.getRecord();
}
public Pagereference saveStudent() {
try {
Upsert student;
return new Pagereference('/' + student.Id);
}
catch(DMLException de) {
Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, de.getDmlMessage(0)));
return NULL;
}
catch(Exception e) {
Apexpages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.FATAL, e.getMessage()));
return NULL;
}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha