+ Start a Discussion
shan876shan876 

Validation Rule?? Please help??

What is wrong with this:

Basically saying: If the partner is HP and Sales_Discount has been changed and it is greater then 40% then cause an error to occur.. if not then go to the next scenario and say if Partner is Geo, and so fourth...

 

IF(AND(Quote__r.Partner_Direct__c = 'HP' , AND(ISCHANGED(Sales_Discount__c),OR(Sales_Discount__c>0.40))), IF(AND(Quote__r.Partner_Direct__c = 'GeoBridge' , AND(ISCHANGED(Sales_Discount__c),OR(Sales_Discount__c>0.35))), true,null))

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Nik07Nik07

This must work

 

 

(didn't test it)

 

 

AND( OR (AND(Quote__r.Partner_Direct__c = 'A' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.50,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'B' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.60 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'C' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name == "System Administrator"), AND(Quote__r.Partner_Direct__c = 'D' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'E' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.70 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'F' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.66 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='G' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='H' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ) ), $Profile.Name <> "System Administrator" )

 

 

 

All Answers

Nik07Nik07

Hi,

 

Try this:

 

OR (AND(Quote__r.Partner_Direct__c = 'HP' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40), AND(Quote__r.Partner_Direct__c = 'GeoBridge' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35))

 


 

shan876shan876

Great but when I place in where profile is not equal to sys administrator it did not work...

 

OR (AND(Quote__r.Partner_Direct__c = 'HP' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40),$Profile.Name <> "System Administrator", AND(Quote__r.Partner_Direct__c = 'GeoBridge' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35) ,$Profile.Name <> "System Administrator")

 Only System Admins can change the value if it exceeds the discount...

Any ideas?? Thanks

 

 

shan876shan876

So I try the following:

 

OR (AND(Quote__r.Partner_Direct__c = 'A' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.50,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'B' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.60 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'C' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name == "System Administrator"), AND(Quote__r.Partner_Direct__c = 'D' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'E' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.70 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'F' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.66 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='G' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='H' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name <> "System Administrator") )

 To test it out I changed the first one to say == to System Admin.. It did not work... Any ideas...

Thanks for helping me out

 

 

Nik07Nik07

This must work

 

 

(didn't test it)

 

 

AND( OR (AND(Quote__r.Partner_Direct__c = 'A' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.50,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'B' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.60 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'C' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name == "System Administrator"), AND(Quote__r.Partner_Direct__c = 'D' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'E' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.70 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c = 'F' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.66 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='G' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ,$Profile.Name <> "System Administrator"), AND(Quote__r.Partner_Direct__c ='H' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35 ) ), $Profile.Name <> "System Administrator" )

 

 

 

This was selected as the best answer
werewolfwerewolf

Your logic here is not working right.  Consider that you have OR(x,y,z) -- if any of x,y, or z is true, then this OR will be true and your validation rule will violate.  As such your sysadmin part is getting OR'd right out (plus you have it there multiply which is weird).

 

What you need instead is an AND in front of the OR.  Let's say z from my example above = "user is not sysadmin" -- then you need AND(z, OR(x,y))

 

So

 

AND (
    $Profile.Name <> "System Administrator",
    OR (
        AND(Quote__r.Partner_Direct__c = 'HP' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.40),
        AND(Quote__r.Partner_Direct__c = 'GeoBridge' , ISCHANGED(Sales_Discount__c), Sales_Discount__c>0.35)
    )
)

 

Note my tabification -- it tends to make formula fields easier to follow.  I make my formula fields in Textpad to tabify them like this before I move them into the woeful formula field editor.