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
cloud machinecloud machine 

Client should not be able to select future date

I have a VF page which has a date field, i have a validation on it but its working in a standard way but its not working in VF page with class even after using page messages functionality.

souvik9086souvik9086

Validation Rule is object based. It has nothing to do with standard or custom page.

Can you share what is the validation rule which is not working in your page?

 

Thanks

cloud machinecloud machine

Date__c > Today()

cloud machinecloud machine

The above is working normally and if i use same field in visual force page then its not working

souvik9086souvik9086
You used Date__c this field in your Custom Page. right?
cloud machinecloud machine

ya i used

cloud machinecloud machine

 The Validation is working but its not displaying error msg even after using page messages

souvik9086souvik9086

STRANGE !!

 

If that is the case you can do a workaround, you can add that condition in your custom controller and use addError method of salesforce

 

if(obj.Date__c > System.Today()) {

 

obj.Date__c.addError('Your Error Message');

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

VennilaVennila

Hi, 

 

Have you used try and catch for the function. If you are missing try and catch, the validation will not show , even you are using apex:pagemessages.

kevin lamkevin lam

Do you have the immediate attribute set to true?

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

Eventhough you set up <ape:pagemessages/> in your page, it wont display the error because you might have some conditions changed to the function 'Save()' or 'Edit()'.

 

So, you must use exception handling to solve this type of issues. I too got stucked in the same problem before. So only i can be sure about it.

 

Anyways, try using the following eg,

 

public class egController{

   pulbic void save(){

        try{

             //implement your logic here

        }

       catch(Exception e){

             ApexPages.addMessages(e);

        }

   }

}

 

 

Hope this will help you...!