+ Start a Discussion
Kumar Saurav 16Kumar Saurav 16 

When to use 'OR', 'AND', NOT while writing a validation rule


I am a newbie in salesforce and eager to get familiar with this platform. Can someone clarify me as to why we begin writing a validation rule with OR, AND , NOT? Further more, why do we need to use them. Can we not simply use keywords like 'IF' to mention a condition, in oreder to validate our code or application module?
Thanks in advance.
Best Answer chosen by Kumar Saurav 16
sfdcMonkey.comsfdcMonkey.com
hi kumar 
done we understand with it by a simple  Account Address Validation Rules
when you create validation rules with multiple conditions you need to use these Operators 
let assumewe want  Validates that the account Billing State/Province is a valid two-character abbreviation if Billing Country is CA or CAN.

so it write like that
AND (
   OR( BillingCountry = "CA", BillingCountry="CAN"),
   OR( LEN(BillingState) < 2,
   NOT(
CONTAINS("AB:BC:MB:NB:NL:NT:NS:NU:ON:PC:QC:SK:YT", BillingState)
         )
        )
    )

explain-:
AND() = 
Returns a TRUE response if all values are true; returns a FALSE response if one or more values are false. Use this function as an alternative to the operator && (AND).
ex-:   IF(AND(Price<1,Quantity<1),"Small", null)

OR() = Determines if expressions are true or false. Returns TRUE if any expression is true. Returns FALSE if all expressions are false. Use this function as an alternative to the operator || (OR).

ex-: IF(OR(ISPICKVAL(Priority, "High"), ISPICKVAL(Status, "New")), ROUND(NOW()-CreatedDate, 0), null)​

NOT() = Returns FALSE for TRUE and TRUE for FALSE.
ex- : IF(NOT(ISPICKVAL(Status, "Closed")), ROUND(NOW()-CreatedDate, 0), null

Thanks 
i hop its helps you 


 

All Answers

sfdcMonkey.comsfdcMonkey.com

hi Kumar 
you got your answer below link 
https://help.salesforce.com/HTViewHelpDoc?id=fields_validation_rules_tips.htm
 

Thanks 
Please mark it best answer if it helps you :)

Kumar Saurav 16Kumar Saurav 16
@soni piyush, my question remains unanswered. I have no problem in writing the logic behind the rule. It is just that I dont understand when to use OR, NOT , AND as a prefix to the formula written as validation rule.
sfdcMonkey.comsfdcMonkey.com
hi kumar 
done we understand with it by a simple  Account Address Validation Rules
when you create validation rules with multiple conditions you need to use these Operators 
let assumewe want  Validates that the account Billing State/Province is a valid two-character abbreviation if Billing Country is CA or CAN.

so it write like that
AND (
   OR( BillingCountry = "CA", BillingCountry="CAN"),
   OR( LEN(BillingState) < 2,
   NOT(
CONTAINS("AB:BC:MB:NB:NL:NT:NS:NU:ON:PC:QC:SK:YT", BillingState)
         )
        )
    )

explain-:
AND() = 
Returns a TRUE response if all values are true; returns a FALSE response if one or more values are false. Use this function as an alternative to the operator && (AND).
ex-:   IF(AND(Price<1,Quantity<1),"Small", null)

OR() = Determines if expressions are true or false. Returns TRUE if any expression is true. Returns FALSE if all expressions are false. Use this function as an alternative to the operator || (OR).

ex-: IF(OR(ISPICKVAL(Priority, "High"), ISPICKVAL(Status, "New")), ROUND(NOW()-CreatedDate, 0), null)​

NOT() = Returns FALSE for TRUE and TRUE for FALSE.
ex- : IF(NOT(ISPICKVAL(Status, "Closed")), ROUND(NOW()-CreatedDate, 0), null

Thanks 
i hop its helps you 


 
This was selected as the best answer
Kumar Saurav 16Kumar Saurav 16
Thanks for your help @soni piyush.
Samrendra Singh 1Samrendra Singh 1
Hi Everyone,

I need your help in writing a validation rule for the below scenario-

Object Name: Asset

The custom field name where validation rule needs to be written: AssetName__c
Logic: The Asset Name field is required if Asset_Type__c is X3rd_Party_Assets__c  or N_A_Assets__c, else blank

I really appreciate your quick help.

Many thanks,
Sam