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
Ritika JRitika J 

Different picklist values depending on 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.

 

 

Any idea , how this can be achieved .

 

Thanks in advance

RJoshi

Navatar_DbSupNavatar_DbSup

Hi,

 

 

You can have picklist values based on your lookup field as, you have to write a action function in your code and you will have to call JavaScript function of action function on onselect of lookup field then this action will call a controller method in which you will have to add your picklist value in your selectoption list for your picklist based on lookup field value and then rerender your portion that belongs to your picklist field.

 

You can refer the below code 

 

// VF page

<apex:page controller="changemultipicklistvalue" id="page" >
<script>
function callonlookup(val)
{
   // alert('check'+val.value);
    callpicklistmethod(val.value);
    
}
</script>

  <apex:form id="frm" >
  <apex:inputField value="{!con.accountid}" id="lookup" onchange="callonlookup(this)"/>
  <apex:actionFunction name="callpicklistmethod" reRender="outputpanel1" action="{!changepicklistvalue}"><apex:param name="conid" value="" assignTo="{!lookupvalue}"/></apex:actionFunction>
  <apex:outputPanel id="outputpanel1" >
  <apex:selectList size="1" >
<apex:selectOptions value="{!options}"/>
  </apex:selectList>
  
  </apex:outputPanel>
  
  
  
  </apex:form>
</apex:page>

//Controller
public class changemultipicklistvalue
{
    public contact con{get;set;}
    public List<SelectOption> options{get;set;}
    public string lookupvalue{get;set;}
    
public changemultipicklistvalue()
{
    con=new contact();
     options = new List<SelectOption>(); 
     Schema.DescribeFieldResult F = contact.number__c.getDescribe();
      List<Schema.PicklistEntry> ple = f.getPicklistValues();
                     for( Schema.PicklistEntry f1 : ple)
                     {
                          options.add(new SelectOption(f1.getLabel(), f1.getValue()));
                     } 
}


public void changepicklistvalue()
{
    if(lookupvalue=='aa')
    {
        options = new List<SelectOption>(); 
        Schema.DescribeFieldResult F = contact.number__c.getDescribe();
        List<Schema.PicklistEntry> ple = f.getPicklistValues();
        for( Schema.PicklistEntry f1 : ple)
        {
                    if(integer.valueof(f1.getLabel())>5)
                    {
                     options.add(new SelectOption(f1.getLabel(), f1.getValue()));
                     }
        } 
    }
}

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.