Friday, April 24, 2015

Salesforce Datetime in a Validation Rule

Salesforce Date Time in a Validation Rule

Recently I had to put in a very simple condition into a validation rule where we didn't want the validation rule to fire for records we created in the past, only on records we created going forward.

So I just wanted to put into the condition formula something that said the created data had to be greater than a set date, here is what I used:

DATEVALUE(CreatedDate) > DATEVALUE("2015-04-24") 


Because the CreatedDate is a datetime field I just used the DATEVALUE field and it worked like a charm!

Now my validation rule which is very simple looks like this and will only fire on records we create from April 24th and forward.

AND( 
     ISPICKVAL(Consulting_Type__c , 'Support – Time Bound'), 
     ISBLANK(Support_End_Date__c ), 
     DATEVALUE(CreatedDate) > DATEVALUE("2015-04-24") 
)