Authored by Zishan Razzaq

Sunday, September 25, 2011

Validation Rules Using 'AND' 'OR' Functionality Within Salesforce.com

Hi all:
  Scenario:
   Need to write a validation rule if a certain checkbox is check, either one field or another field has to be filled in. So it is one or the other.

Solution:
To utilize And and OR functionality within the Validation rule.

Create these fields on the Account object or substitute your fields.
Discount Applicable | Attribute: Checkbox
Amount: Currency
Percentage: Number (10,2)
Error should appear at top of Page stating: Since Discount Applicable is true then Amount OR Percentage is required.

Go to Setup | Customize | Object (Account) | Validation Rules | New

Breakdown the validation Rule:
Discount Applicable = True
This is a must to have so it would go under AND requirement.
Amount is blank OR Percentage is Blank. this is the OR part of the validation rule.

Putting it together:
Start off with OR( then place in the AND functionality within the OR functionality), You can see the formula below where I start off with the OR Statement then the Final should always be there...

OR(
AND(ISBLANK(If_Yes_Percentage__c),
ISBLANK(If_Yes_Amount__c), Is_There_a_Discount_Applicable__c = True))

This is it... Hope this helps..
Thanks
Z
VisualForce Made Easy
MMAXTRA
Watch Me Fight 

2 comments:

  1. I'm confused. Could you explain why it wouldn't be:

    OR(
    AND(ISBLANK(If_Yes_Percentage__c),
    ISBLANK(If_Yes_Amount__c)), Is_There_a_Discount_Applicable__c = True)

    which is basically OR(AND(condition 1, condition 2),condition 3) while I think you wrote it as OR(AND(condition 1, condition 2, condition 3))

    I'm probably way off which is why I'm asking. Thanks.

    ReplyDelete
  2. Hi Judi:
    The rule that you wrote tells the function or rule that both Percentage and amount needs to be filled in then discount applicable. But when I did try your formula out and I had Percentage = 100 and Amount =70 and discount = true, it still bought up an error, until I took away discount = true.
    The formula I have demonstrated here describes:
    OR(
    AND(ISBLANK(If_Yes_Percentage__c),
    ISBLANK(If_Yes_Amount__c), Is_There_a_Discount_Applicable__c = True))
    when Percentage OR amount is filled but when Discount is applied. So either or but Discount has to be applied to the rule for it to work.
    Hope this Helps
    Zishan

    ReplyDelete