+ Start a Discussion
Shravya Rama 9Shravya Rama 9 

Apex Errors not functioning

if(res.Start__c < system.now()){
 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' Start Time should always be greater than current time.'));                    
            }

 if(res.end__c < system.now()){
 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' End Time should always be greater than current time.'));   
            }
I also used  <apex:pageMessages/> in VF page.

Can anybody kindly let me know where am I wrong?
 
Best Answer chosen by Shravya Rama 9
Shravya Rama 9Shravya Rama 9
Sorry, my mistake. Its working fine :)

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hey Shravana,

What is the data type of Start__c and End__c. They should be of type DateTime. Thanks.
Shravya Rama 9Shravya Rama 9
Hi ravi,

Yeah they are of DateTime datatype. And also the System.debug of Start__c and End_c are not showing the correct times. I have also thrown few other error messages from the same method which works perfectly fine but I dont know whats wrong with the above two.
Ravi Dutt SharmaRavi Dutt Sharma
The time that is shown in debug logs is according to time zone. Can you tell me the value of Start__c which is getting printed in debug. Thanks.
Shravya Rama 9Shravya Rama 9
if(res.End__c != null && res.Start__c!=null ) {
            
            system.debug('system.now()'+system.now());
            
            system.debug('res.Start__c'+res.Start__c);
            system.debug('res.end__c'+res.Start__c);
            
            if(res.Start__c < system.now()){
                
                
                system.debug('Start__c < system.now');
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' Start Time should always be greater than current time.'));    
                
            }
            if(res.end__c < system.now()){
                system.debug('end__c < system.now');
                
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,' End Time should always be greater than start time.'));   
            }
}
Following is the result in debug, without any errors in the page.

User-added image
 
Ravi Dutt SharmaRavi Dutt Sharma
I tried to reproduce this in my org, but it is working fine for me. I created two date time fields and compared them like the way you compared it in your org. Seems to be working fine.

User-added image
Shravya Rama 9Shravya Rama 9
Sorry, my mistake. Its working fine :)
This was selected as the best answer