I have following code –
Page –
<apex:selectList value="{!selectContactId}" multiselect="false" size="1" id="RelatedContact">
<apex:selectOptions value="{!relatedContacts}"/>
</apex:selectList>
Controller –
public List<SelectOption> getRelatedContacts()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('', '-None-'));
if(opportunityObj != null && GeneralUtil.CheckBlank(opportunityObj.accountid))
{
for(Contact contactObj: [select id,name from contact where accountid=:opportunityObj.accountid limit 999]) //controller can have only 1000 items in list :(
{
options.add(new SelectOption(contactObj.id, contactObj.name));
}
}
return options;
}
this doesn't work for more than 1000 values any ways to get around this ?
Best Answer
I'd say "you're doing it wrong" ;)
Every time you're hitting a limit like that you should stop and ask if that's really what you need to do. Even if you'd be able to input 50K contacts here - what would usability of such monster be? How is user expected to scroll through this? I'd say a lookup with a search function is really the way to go, that's what it is for.
Have you considered using an autocomplete? Jeff Douglas's blog contains a really nice example on dynamic search - it's not exactly autocompletion but you shouldn't have too much trouble modifying it.
An alternative might be @BobBuzzard's VF lookup
Or simply marry jqueryUI autocomplete and a @RemoteAction
But if you insist on reading further... ;)
So you can get your query results, build a
<List<List<SelectOption>>
for example and then have a combo of<apex:repeat>
+<apex:selectOptions>
... I still advise against doing this though ;)