+ Start a Discussion
sfbatchsfbatch 

CLUMSY VALIDATION RULE

Guys Will you please explain me the following Validation rule, as I have very basic knowledge on date validation rules I am unable to understand the following date validation rule.  Currently we are stuck in this validation rule in cases, which are clearing basing on priority. We are giving support to our customers basing on priority, the following is our old priority and issue clearance for our customers and we have to apply new priority rules to serve our customers. 

IF(
ISNULL( FLAGS__ViewedFlag__c),
null,
DATETIMEVALUE(TEXT(
DATEVALUE(FLAGS__ViewedFlag__c+
CASE(TEXT(Priority),
'P1',
CASE(MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7),
1,1,
6,3,
0,2,
2,1,
3,1,
4,1,
3),
'P2',
CASE(MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7),

1,2,
6,4,
0,3,
2,2,
3,2,
4),
'P3',
CASE(MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7),
1,3,
6,5,
4,5,
5,5,
0,4,
2,3,
3,5,
5),
CASE(MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7),
6,9,
0,10,
7))))
Best Answer chosen by sfbatch
Dev.AshishDev.Ashish
ISNULL( FLAGS__ViewedFlag__c) is to check if FLAGS__ViewedFlag__c field is null or not, if it is not null remaining logic (below) will execute.

"DATETIMEVALUE(TEXT(
DATEVALUE(FLAGS__ViewedFlag__c +
above formula is to return DateTime value of Date which will come after adding FLAGS__ViewedFlag__c and logic after "+" sign.

"CASE(TEXT(Priority),
'P1',"
above logic determine if Piriority field is P1.

CASE(MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7),
1,1,
6,3,
0,2,
2,1,
3,1,
4,1,
3),,"

above logic finds the day of date FLAGS__ViewedFlag__c, like if MOD(DATEVALUE(FLAGS__ViewedFlag__c)- DATE(1900, 1, 7),7) return 1 day will be Monday and value returned will be 1 , if returned value from MOD is 6 the case statement return value will be 3. If none matches returned value from case statement would be 3.  More on finding days in week @ http://help.salesforce.com/apex/HTViewSolution?id=000004512&language=en_US

Similarly for prioty P2 and P3. If none Pirority matches it will return 7.