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
ErikTheTinkererErikTheTinkerer 

How to create a custom set of dependant picklists, with more than 250 values

Hello braintrust,

 

I have a requirement to create a set of dependant picklists, but I want the controlling field to have multiselect piclist behavior...

Also, my 2nd picklist may have more than 250 values.

 

So I assume I have to somehow create this programmatically.

 

Can visualforce and apex do this?

Or do I have to resort to AJAX?

 

Thanks!

 

Erik

ErikTheTinkererErikTheTinkerer

Found the info:

 

You can create custom picklists using Visualforce and Apex, by creating an Visualforce Controller Extension. SeeChapter 12, page 371, of the Developer Guide, for a detailed example of a picklist, populated with values via Apex.

 

I believe this could even allow you to extend your # of picklist values beyond the default of 250 items (though i haven't tried it.)

 

ErikTheTinkererErikTheTinkerer

A bit more

 

 

VF has a tag called <apex:selectList> to create picklists that are driven by Apex code. In your case, you might use Apex code to query a custom object with the picklist values. You could hardcode the values in Apex but with 250 values, table driven seems to be a better approach...

 

 

 

 

Example: <!-- Page: --> <apex:page controller="sampleCon"> <apex:form> <apex:selectList value="{!countries}" multiselect="true"> <apex:selectOptions value="{!items}"/> </apex:selectList><p/> <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/> </apex:form> <apex:outputPanel id="out"> <apex:actionstatus id="status" startText="testing..."> <apex:facet name="stop"> <apex:outputPanel> <p>You have selected:</p> <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> </apex:page> /*** Controller: ***/ public class sampleCon { String[] countries = new String[]{}; public PageReference test() { return null; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('US','US')); options.add(new SelectOption('CANADA','Canada')); options.add(new SelectOption('MEXICO','Mexico')); return options; } public String[] getCountries() { return countries; } public void setCountries(String[] countries) { this.countries = countries; } }