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