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
Balakumar RamachandranBalakumar Ramachandran 

Dependent picklist selecting in Apex

Hi all,

I am struck where i am not able to show my dependent picklist values using apex. Can anyone suggest how to proceed further ?

the reason i am running  behind apex is VF Page does not allow to show more than 10 dependent standard picklist values even though all these fields are stored in API...

controller
-------------
 public List<SelectOption> getSalesBu()
    {
      List<SelectOption> options = new List<SelectOption>();
      options.add(new SelectOption('--None--','--None--'));
 
      Schema.DescribeFieldResult SBU = Opportunity.Sales_BU2__c.getDescribe();
      List<Schema.PicklistEntry> ple = SBU.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
            {
                options.add(new SelectOption(f.getLabel(), f.getValue()));
            }
       return options;

    }
    

     public List<SelectOption> getProductTypeSalesBu()
    {
      List<SelectOption> options = new List<SelectOption>();
      system.debug('------------SelectedValue-------------'+selectedSalesBu); 
      if(selectedSalesBu != NULL)
      { 
            options.add(new SelectOption('--None--','--None--'));

      for (Opportunity proSales : [select Id,Name,Product_Type_Sales_BU__c from Opportunity Where Sales_BU2__c = :selectedSalesBu])
            {
            
                    options.add(new SelectOption(proSales.id,proSales.name));
             }
       

       }return options;
    } 

i need to show Product_Type_Sales_BU__c  values based on selected Sales BU Selection. I am seeing selected SalesBU Value passed to Query but how to show Product_Type_Sales_BU__c  values..

if i change from

                    options.add(new SelectOption(proSales.id,proSales.name));

to 
                    options.add(new SelectOption(proSales.id,proSales.Product_Type_Sales_BU__c));

i get an error..
Balakumar RamachandranBalakumar Ramachandran
Thanks for your response.
I saw earlier that website for titancronus but i am not sure how to use it in my VF Pages.
 
Chandra Sekhar CH N VChandra Sekhar CH N V
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
If you are reading this post in the future (and who isn't?), you will find a very concise solution to the dependent picklist values problem here: https://glyntalkssalesforce.blogspot.com/2018/08/dependent-picklist-values-in-apex.html

One method, about 30 lines of code.  And the blog includes test code, too!  I hope it helps you!