+ Start a Discussion
BantiBanti 

Validation Rule for Multiple Fields

Hi,

 

i have 20 fields. i,e Day 1, Day2, Day3, Day4....Day20

 

i need to write a single validation rule for all  those fields to allow only 1, 0.5, 0 

 

Please help me.

 

Thanks

PrabhaPrabha

I would suggest to change the field api name to d1__c, d2__c to get minimum number of characters in the formula.

 

the solution goes like this.

 

OR(NOT(OR(d1__c=1,d1__c=0.5,d1__c=0)),NOT(OR(d2__c=1,d2__c=0.5,d2__c=0)),........)

 

HTH

Prabhan

Naveen NelavelliNaveen Nelavelli

you better to use apex code to display custome message ,ie to guide user exactly which field is failing... 

 

public boolean chk(Double day){

try{

if(day==1 or day==0.5 or day==0){

     return true;

}

else{

     throw new  myException("msg);

      RETURN FALSE;

}

}

catch(My Exception){

 

//display apex message

}

//call method like this

chk(day1__c);

chk(day2__c);

if you like this solution,we can still optimize code...just let me know

 

 

BantiBanti

Thanks to Praabha , Naveen for your answers.

BantiBanti

PrabhaPrabha

That is strange...

Anyway, why would u define it 17 when u want to store just one character... can u make Length - 1, Decimal Places - 1 on the field definition and check?

That must have been your definition issue.