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
springeverspringever 

Different picklist values depending on lookup input

Different picklist values dependingon user input.

 

Hi,

 

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

 

 

Nantha_WipNantha_Wip

Hi,

 

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

 

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

 

 

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>();
        system.debug('@@@@@@@@@@@'+mylookup.accountid);

    //change with your conditions
        if(mylookup.accountid=='0019000000LkwMVAAZ')
        {
            options.add(new selectOption('', 'a'));
            options.add(new selectOption('1', 'aa'));
            
        }
        else
        {
            options.add(new selectOption('', 'b'));
            options.add(new selectOption('1', 'bb'));
        }
    }
}

 

 

Mark as answer if it solves your issue