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
Shane QuiringShane Quiring 

How to auto populate picklist field depending on another picklist field?

Hi, I am very very new to APEX, but not new to Salesforce. I need to auto populate a picklist field on related obect from the parent object, due to the other picklist field is a controlling field for another multi-select picklist field. Here are the details: I would like to take the "BillingState" field from Accounts and use the value there to autopopluate a picklist field, "State__c" on Cases then pass the information to the field "Customer_State__c" on my custom object, Internal_Buy_Rate__c. I did find the following answer, https://developer.salesforce.com/forums/ForumsMain?id=906F000000093U9IAI, I am stuck on how to modify this to suit my purposes for the text field from accounts and than pass that information down to my related objects. Any help would be greatly appreciated. 

Thank-you.

Shane
Best Answer chosen by Shane Quiring
dev_sfdc1dev_sfdc1
Hi Shane Quiring,

This is for dynamic autopopulating picklist value based on this sample you can try in apex class:

public string selectBillingState{get;set;} 

    public list<selectOption> getBillingState()
    {
        list<selectOption> options = new list<selectOption>();
        options.add(new selectOption('','-None-'));
        list<Account> houres= [Select Id,BillingState from Account]; 
        
        for(Account hr : houres)
        {
           
               options.add(new selectOption(hr.BillingState,hr.BillingState));
             
          
        }
       
        return options;
    }



Thank You

All Answers

dev_sfdc1dev_sfdc1
Hi Shane Quiring,

This is for dynamic autopopulating picklist value based on this sample you can try in apex class:

public string selectBillingState{get;set;} 

    public list<selectOption> getBillingState()
    {
        list<selectOption> options = new list<selectOption>();
        options.add(new selectOption('','-None-'));
        list<Account> houres= [Select Id,BillingState from Account]; 
        
        for(Account hr : houres)
        {
           
               options.add(new selectOption(hr.BillingState,hr.BillingState));
             
          
        }
       
        return options;
    }



Thank You

This was selected as the best answer
Shane QuiringShane Quiring
Hi dev_sfdc1,

Thanks for the information and the help. Knee deep in developing and a Go Live.