i want to make an this.addError with a condition on a date field this condition must get the error if the date is write in a wrong way like this:


i have already an if condition in this way:

 if( null == (this.account.customdate__c) )

and i have it in my visualforce page but when i press my command the error don't appear but i cant' go in the next page's step

<apex:inputField id="IdR" value="{!Account.customdate__c}" styleClass="RemoveNone" />

How i can do?

  • Is your custom field of type Date? Jan 26, 2017 at 14:47
  • yes @MartinLezer
    – Amiga 500
    Jan 26, 2017 at 14:59
  • Ok. So it doesn't work that way. The Date type value is independent from the way its displayed. Jan 26, 2017 at 15:06
  • how your custom date is calculated at the time of saving? Jan 26, 2017 at 15:13
  • what do you want to talk about? @SantanuBoral
    – Amiga 500
    Jan 26, 2017 at 15:59

1 Answer 1


Though I am not sure of the exact error that you are facing, but I think the below pointers will help you;

  1. customdate__c is of type Date

If this date field you have included in you VF page like

<apex:inputField value="account.customdate__c"/>
then, when you click on any commandbutton or commandlink, it get validate itself before your action method is called and the error will be shown. You cannot handle it in server side because this value will never reach server side.

    2. customdate__c is of type Text

Then you can try

    try {
    } catch (System.TypeException te) {
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Not a valid date.');
} else {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Date value cannot be null.');

From the code above I do think you are using it in a ApexController. In case of trigger use record.addError() in place of apexMessages.

  • i have it in my visualforce page: but when i press my command the error don't appear but i cant' go in the next page step
    – Amiga 500
    Jan 27, 2017 at 14:48
  • 1
    Add <apex:pagemessages /> in your page and try. Jan 27, 2017 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .