使用联系人填充选择列表
我想使用 apex:selectList 来填充联系人。问题是它给出了一个错误
Collection size 3,403 exceeds maximum size of 1,000
这是因为我有3403个联系人,而Vf对VF页面中的集合有限制。
我想将初始联系人集限制为 <1000,并且当用户开始输入我想要查询的联系人的字符时。例如,如果用户输入 Ji,我想查询联系人以检索以 JI 开头的记录。
这可以吗?
<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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在查询中使用通配符来执行此操作 - 因此您需要在页面中添加一个
元素以允许他们输入搜索词,该搜索词写为到控制器中的字符串变量。然后添加一个搜索按钮来运行查询并使用新的联系人列表重新呈现列表。控制器的重要部分如下所示:
您可以使用操作函数执行搜索,并从输入字段的 onChange 事件触发它,但使用按钮进行搜索将使整个事情更加响应(IMO)从用户的角度来看。
注意:我即时编写了这段代码,您可能不能以这种方式将“%”与搜索词连接起来,或者在直接查询时甚至不需要这样做。通常在这些情况下,由于其他要求,我不得不使用动态 SOQL,在字符串中构建查询:
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:
有几个选项可以获取您想要的功能。这取决于您想要的解决方案的复杂程度,但总有解决方案。
您可能需要考虑在控制器中使用 jQuery 和 SOSL(搜索语言)。以下是 Salesforce 中使用 Ajax API 进行 jQuery 自动完成的示例。点击下面的链接:
http://matthewkeefe-developer-edition.na8.force.com/jQueryAutocompleteWithAjaxAPI
另外,请查看 Tehnrd 的帖子“超酷高级查找组件"作为另一个选项。
There are a few options to get the functionality you'd like. It depends on how complicated of a solution you'd like, but there is always a solution.
You may want to consider using jQuery and SOSL (Search Language) in a controller. Here's an example of jQuery autocomplete with the Ajax API in Salesforce. Click the link below:
http://matthewkeefe-developer-edition.na8.force.com/jQueryAutocompleteWithAjaxAPI
Also, check out Tehnrd's post "Super Cool Advanced Lookup Component" for another option.