+ Start a Discussion

Different picklist values depending on lookup input

Different picklist values dependingon user input.




I have a requirement in which i will have to display different picklist values  depending on the value selected by user in a lookup field.

Picklist values from  lookup selceted values.

 eg:bank's name is A  input,picklist values is aa and aaa.

         bank's name is B  input,picklist values is bb and bbb.


Any idea , how this can be achieved .


Thanks in advance






Find the below sample VF and controller class for dynamic picklist based on lookup field


<apex:page controller="controller1">
  <apex:inputField value="{!mylookup.Accountid}">
      <apex:actionSupport event="onchange" action="{!changeValue}" rerender="dependentPick,check1"/>
  <apex:selectList id="dependentPick" size="1" multiselect="false">
      <apex:selectOptions id="renderedVal"  value="{!Picklistvalue}"></apex:selectOptions>



APEX class:

public class controller1
    public string inputval{get;set;}
    public contact mylookup{get;set;}
    public controller1()
        mylookup=new contact ();
    List<selectOption> options =new List<selectOption>();
    public List<selectOption> getPicklistvalue()
            return options;
    public void changeValue()
        options =new List<selectOption>();

    //change with your conditions
            options.add(new selectOption('', 'a'));
            options.add(new selectOption('1', 'aa'));
            options.add(new selectOption('', 'b'));
            options.add(new selectOption('1', 'bb'));



Mark as answer if it solves your issue