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
SainSain 

How to Make Picklist Mandatory(any value Reuqired), if we select any value another Picklist

Hi,

I have a two Picklist A and B, if i select any value in picklist A, it should has to be make Picklist B Mandatory(Required to select  a value in Picklist B).

Please share, Does anyone has some sample code or can point me in the right direction?
Many thanks!!!
Best Answer chosen by Sain
SainSain
Solution for this:

trigger RequirePicklistValue on MyObject__c(before insert, before update) {
for(MyObject__c obj: trigger.new){
//if((obj.Picklist1 =='X' || obj.Picklist1=='Y') && obj.Picklist2 == null){
     if( obj.Picklist1 != null){
            if(obj.Picklist2 == null){
                 obj.Picklist2.addError('value Should be Reuired');
//}
                  }
              }
       }
}

Regards,
Shaik

All Answers

Jerome LusinchiJerome Lusinchi
Hi,

You can use dependant picklists for that, and set the second picklist field as required on the page layout.
The second picklist will be required only if there is a possible value based on the first picklist value.

Jerome
SainSain
Solution for this:

trigger RequirePicklistValue on MyObject__c(before insert, before update) {
for(MyObject__c obj: trigger.new){
//if((obj.Picklist1 =='X' || obj.Picklist1=='Y') && obj.Picklist2 == null){
     if( obj.Picklist1 != null){
            if(obj.Picklist2 == null){
                 obj.Picklist2.addError('value Should be Reuired');
//}
                  }
              }
       }
}

Regards,
Shaik
This was selected as the best answer