I want to use a apex:selectList to populate contacts. The problem is that it gives an error
Collection size 3,403 exceeds maximum size of 1,000
This is because i have 3403 contacts, and Vf has limitation on the collections in the VF page.
I want to limit the inital set of contacts to <1000, and as the user starts typing in the characters i would want to query the contacts. For ex if the user types in Ji i want to query the contacts to retrieve records starting with JI.
Is this possible to do?
<apex:selectlist id="ClientsSearch" value="{!Appointment.Client__c}"
size="1" required="true" rendered="{!NOT (SearchMode)}">
<apex:selectOptions value="{!Clients}" />
</apex:selectlist>
public List<SelectOption> getClients() {
List<SelectOption> options = new List<SelectOption>();
List<Contact> Clients = [Select id, Name From Contact order by Name];
options.add(new SelectOption('0001', '--Select--'));
for(Contact c : Clients ){
options.add(new SelectOption(c.id, c.Name));
}
return options;
}
You can use wild cards in your query to do this — so you’ll want to add an
<apex:inputText>element in your page to allow them to enter a search term, which writes to a string variable in the controller. Then add a search button to run the query and re-render the list with the new list of contacts.The important parts of the controller will look something like this:
You could perform the search using an action function and firing it from the onChange event of the input field but having a button to do the search will make the whole thing more response (IMO) from the user’s point of view.
Note: I wrote this code on the fly, it may be that you can’t just concat ‘%’ with the search term in this manner or maybe that you don’t even need to when querying directly. Usually in these cases I’ve had to utilise dynamic SOQL due to other requirements, where you build up the query in a string: