[SalesForce] Validation rule if Opportunity is closed won

I want to make some fields required, if the Opportunity is closed won. So I tried the following code, but it does not trigger, so the AND seems to be always false, but I do not know why.

AND(
ISPICKVAL( StageName , "08 - Closed Won"),    Order_Form_uploaded__c,
Contract.Contract_uploaded__c,   
NOT(ISPICKVAL( Account.Type , "Customer")),
NOT(ISPICKVAL(  Account.Account_Status__c , "4  Avoid: Current Client")),
ISBLANK(PO_Date__c),
ISBLANK( Licensing_Start__c ),
ISBLANK( Quote_Number__c ),
NOT(HasOpportunityLineItem  ) 
)

This are my requirements:
IF Opp is closed won and
contract_uploaded tickbox is true,
order_form Tickbox is true,
Account Type = Customer,
Account Status = 4 Avoid: Current Client,
PO Date is not null,
Quote number is not null and
At least one product is added,
then show error message

I have checked all fields but nothing happens..
Is it possible that the problem is related to some fields not yet "created"? Will ISBLANK(Quote_Number__c) return true if there is no such record created yet?

Thanks!

Best Answer

You've confused AND and OR with how we typically use the words in English. In Boolean logic, AND means all conditions must be met, while OR means any condition must be met. Since you're checking if any of several fields are blank, you want an error if any of those fields are blank, while as written, this validation rule will only show an error if all of those fields are blank.

As an aside, you should consider separate validation rules for each field. This allows you to place the error on the appropriate field(s) that the user needs to fill out. You are allowed hundreds of validation rules per object, so there's no need to "conserve" them.

Your rule should probably read:

AND(
  ISPICKVAL( StageName , "08 - Closed Won"),
  NOT(ISPICKVAL( Account.Type , "Customer")),
  NOT(ISPICKVAL(  Account.Account_Status__c , "4  Avoid: Current Client")),
  OR(
    Order_Form_uploaded__c,
    Contract.Contract_uploaded__c,   
    ISBLANK(PO_Date__c),
    ISBLANK( Licensing_Start__c ),
    ISBLANK( Quote_Number__c ),
    NOT(HasOpportunityLineItem  ) 
  )
)
Related Topic