function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ManzaManza 

Validation Rule not working as expected

I have the following fields in my object:


Picklist: StageName
Picklist: Closed_Lost_Reason_Category__c
Text:     Lost_Reason__c

My validation rule should be trigger if the StageName is selected Closed Lost and the other fields (Closed_Lost_Reason_Category__c,Lost_Reason__c) are left empty

I have done the following but it only validates StageName and Lost_Reason__c

IF(
text(StageName) = "Closed Lost" &&
Lost_Reason__c  = "" &&
ISBLANK(TEXT(Closed_Lost_Reason_Category__c)),
TRUE,FALSE
)


The weird part is that if I do: it doesnt validate Lost_Reason__c

IF(
text(StageName) = "Closed Lost" &&
ISBLANK(TEXT(Closed_Lost_Reason_Category__c)) &&
Lost_Reason__c  = "",
TRUE,FALSE
)

I dont understand what I am doing wrong
Best Answer chosen by Manza
PratikPratik (Salesforce Developers) 
Hi MAnza

Try this:


AND ( (ISPICKVAL(StageName,"closed lost")),
OR(ISPICKVAL(Closed_Lost_Reason_Category__c,''), ISBLANK(Lost_Reason__c) ) )


Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

All Answers

PratikPratik (Salesforce Developers) 
Hi MAnza

Try this:


AND ( (ISPICKVAL(StageName,"closed lost")),
OR(ISPICKVAL(Closed_Lost_Reason_Category__c,''), ISBLANK(Lost_Reason__c) ) )


Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.

This was selected as the best answer
PratikPratik (Salesforce Developers) 
Hi Manza,

Is above mentioned Validation working properly?

In the validation you were checking, it was checking for one field as it was AND condition.

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
ManzaManza

Hi Patrik

It works, however I am a little bit confused of why it does, I initially was doing:
and (logic 1, logic 2, logic 3) but this way was only checking logic 1 and 2, it didnt matter if 3 was empty or not it always let me saved the record, i guess the or is syaing if 1 is missing is true otherwise is false.

Thanks!!!!

PratikPratik (Salesforce Developers) 
Hi Manza 

You logic was (1 AND (2 AND 3) ; so if any one of the  field 2 or 3 is blank, it will False. So it will not check for both the fields.

The current logic  is  (1 AND(2 OR 3), so it will check for both the fields even if any of the field is  blank it will return True. In validation, to fire the error you must return the formula value to True.

Hope it will help you to clear the confusion,

Thanks,
Pratik