Authored by Zishan Razzaq

Tuesday, December 23, 2008

Date Must Be in the Current Month Validation Rule in Salesforce.com

Hi all:
I just had a task for a client, in which I had to create a Validation Rule, and that Validation had to do the following:
  1. On the current Account Record, (It can be Account, Opportunity, Contact etc.)
  2. If the CreatedDate was last Month then the user can not edit the record but if it was not then the user can edit the record.
So this is my Validation Rule for Such a Case:
  1. First thing was, I had to convert CreatedDate to a regular Date value because it was a DateTime Value. So you do that by DATEVALUE(CreatedDate).
  2. Then I stated that if the year of the CreatedDate and Month is not equal to today then basically spit out an error. This is the complete Validation Rule:
OR(
YEAR(DATEVALUE(CreatedDate)) <> YEAR(TODAY()),
MONTH(DATEVALUE(CreatedDate)) <> MONTH(TODAY())
)

I hope this helps... Let me know send me feedback..
Thanks
View my Other Blogs:
VisualForce Made Easy

Salesforce Data Migration Made Easy

No comments:

Post a Comment