0

How can I pass a series of parameters to an unbound drop down from a lookup object?

Would I run a SOQL query and populate a List? Or is there another method to populate a dropdown with a values from a lookup table (and not a pick list)

Here is the VisualForce page where I'd like the unbound control

<apex:outputLabel value="select list " for="type"/>
<apex:selectList size="1" id="type"> 
   <apex:selectOptions value="{!MyOptionsFromController}"/>
</apex:selectList>

2 Answers 2

3

Note that this is an answer to an earlier version of the question.

You are making the field describe call on:

... Business_Unit__c.name ...

which is not a picklist field and so will return a zero length array of PicklistEntry which in turn will result in no select list options.

Use the API name of your picklist field:

DescribeFieldResult result = Business_Unit__c.ApiNameOfPicklistField__c.getDescribe();
4
  • makes sense. I'll rephrase my original question. Look for the edit.
    – tjcinnamon
    Commented Apr 14, 2016 at 13:32
  • I upvoted and re-scoped the question.
    – tjcinnamon
    Commented Apr 14, 2016 at 13:36
  • @tjcinnamon You can populate the values from say a list custom setting or a normal SObject by querying or from say some JSON stored in a static resource or from hard-coding in Apex. But only makes sene if the platform's built in picklist mechanism doesn;t do what you need.
    – Keith C
    Commented Apr 14, 2016 at 14:39
  • It's coming from a lookup because the "picklist" is community user managed. They add their Business Units which are specific to their Account then they associate those to an "Software Application"
    – tjcinnamon
    Commented Apr 14, 2016 at 15:16
0

This is what I did. Big ups to Keith C for pointing me in the right direction

Controller

public List<SelectOption> getUnits()
    {
        List<SelectOption> options = new List<SelectOption>();
        List<Business_Unit__c> units = new List<Business_Unit__c>();
        units = [SELECT Name FROM Business_Unit__c];

        for (Business_Unit__C b: units)
        {
           options.add(new selectOption(b.Name, b.Name));
        }

        return options;
    }

VF Page

<apex:pageBlockSection title="Filter here" collapsible="true" columns="1">
    <apex:outputLabel value="select list " for="type"/>
    <apex:selectList size="1" id="type"> 
        <apex:selectOptions value="{!Units}"/>
    </apex:selectList>
</apex:pageBlockSection>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .