+ Start a Discussion
LAMCORPLAMCORP 

Lookup as a dropdown - Possibly a VF page?

Dear all,

 

Does anyone have some idea / sample code for turning a lookup relationship in a dropdown list?

 

My users are finding it tuff with so many lookup options.

 

Hoping someone can assist. Thanks

 

 

sfdcfoxsfdcfox
public SelectOption[] getContactList() {
    SelectOption[] options = new SelectOption[] { new SelectOption('','-- Select One --') };
    for(Contact tempContact:[SELECT Id,Name FROM Contact WHERE AccountId = :thisAccount.Id ORDER BY Name ASC]) {
        options.add(new SelectOption(String.valueOf(tempContact.Id),tempContact.Name));
    }
    return options;
}

 

    <apex:selectList size="1" multiselect="false" value="{!thisAccount.Primary_Contact__c}">
         <apex:selectOptions value="{!contactList}"/>
    </apex:selectList>

An example using accounts and contacts, as a really contrieved example. Hope this gets you started.