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
steve456steve456 

Help with a Validation Rule

I have two  fiellds on object   Colors    ,   Rejection Reason

 

Colors is MULTISELECT picklist

 

Rejection Reason  is just a picklist 

 

 

Whenever the colors B,C,D,E,F,G  in any combination are selected  Rejection Reason field is mandatory

 

Whenever the color A is selected Rejection Reason is not mandatory

 

 

Whenever the color A is selected along with B,C,D,E,F,G   (any combination as it is a multi select picklist )  Rejection Reason is not mandatory

 

 

Colors has the following values                                                    

A, B ,C ,D,E,F,G ,H      

 

 

I am able to get through all scenarios except the third  

 

 

Can anybody please be a life saver for me                                                                         

Best Answer chosen by Admin (Salesforce Developers) 
Jerun JoseJerun Jose
I just tried this in my personal dev org and it worked.

AND(
NOT(INCLUDES( Multi_Select_picklist__c , "A")),
ISBLANK(TEXT(Type))
)

Type is the normal picklsit field

All Answers

Rocks_SFDCRocks_SFDC

Please use INCLUDES() function in validation rule.

 

Formula: INCLUDES(Colors__c, "A") && NOT(ISBLANK(Rejection_Reason__c))

 

Please accept as solution if it works

 

Thanks,

Anil

 

steve456steve456

Your Solution wi;; not work

 

Formula: INCLUDES(Colors__c, "A") && NOT(ISBLANK(Rejection_Reason__c))

 

 

NOT IS BLANK cannot be used for picklist

 

So we cannot get the functionality 

 

 

 

Jerun JoseJerun Jose
Try this.

AND(
NOT(INCLUDES(Colors__c, "A")),
ISBLANK(TEXT(Rejection_Reason__c))
)
AppyAppy

Trigger Code :- 

trigger Picklist_test on Object1__c (before insert, before update) {

for (Object1__c a:Trigger.new){
string text = 'B;C;D;E;F;G';
Boolean res1 = text.equals(a.Colors__c);
string val1 = a.Colors__c;
list <string> val = val1.split(';');
Boolean res2 = false;

for (string s:val)
{
if (s.equals('A'))
res2 = true;
}

if (res1==true)
{
a.Rejection_Reason__c = 'Mandatory';
}

else if (res2 ==true)
{

a.Rejection_Reason__c = 'Not Mandatory';
}
}
}


Mark SOLVED if it helps :)

steve456steve456

@Jerun  You cannot use a NOT for an include function as it is a multi select pick list

Jerun JoseJerun Jose
I just tried this in my personal dev org and it worked.

AND(
NOT(INCLUDES( Multi_Select_picklist__c , "A")),
ISBLANK(TEXT(Type))
)

Type is the normal picklsit field
This was selected as the best answer
Jerun JoseJerun Jose
Good to have an answer, but I see that you also have a value "H" in your multi-picklist. This validation will throw an error when H is selected and Rejection Reason is blank. Is that okay?
What should happen when H is selected.
steve456steve456

Those are dummy values.The idea of logic is suffice