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
RathishRathish 

Accessing dependant picklist in c#

Does anybody knows how to access the dependant pick list values in c#? I have two picklists and both are related each other. When I change the value in a dropdown list, the related values in the other picklist should load in the next dropdown list. I am able to get the picklist values using DescribeSObjectResult as follows. 
 
SForce.PicklistEntry[] pick = null;
SForce.DescribeSObjectResult obj = binding.describeSObject("Lead");
           
            foreach (SForce.Field f in obj.fields)
            {
                // Is this a picklist and is the field name Type—
                if (f.type == SForce.fieldType.picklist && f.name == "Region__c")
                {
                    pick = f.picklistValues;
                }
            }
            return pick;
 
Thanks
Rathish
RathishRathish

Hi,

I could resolve this problem. Please find the solution.

Input Parameters - PicklistEntry - The picklist entry in the dependent field, region - the controlling field, strRegionSelected - the selected value in the controlling field.

This method will return true if the particular PicklistEntry in the dependent field is valid for the selected value in the controlling field. or it will return false.

public bool GetValidForNodes(SForce.PicklistEntry ppi, SForce.Field region, string strREgionSelected)
      {
         bool blnValid = true;
         SForce.Field controller = region;

         // For each PicklistEntry get all controlling values for which it is valid.
         Bitset validFor = new Bitset(ppi.validFor);
         if (validFor.size() == 0) return false;
         if (controller.type.ToString() == "picklist")
         {
             // The controller is a picklist.  Get all controlling values for which this entry is valid.
             for (int j = 0; j < validFor.size()-1; j++)
             {
                 if (validFor.testBit(j))
                 {
                     if (strREgionSelected == controller.picklistValues[j].value)
                     {
                         return true;
                     }
                }
             }
          }
         return false;
      }