[英]Displaying Records based on keyword from vf page
I have a senario where i will be dispalying input text fieldon vf page,when i enter some value and click on search button the realted accounts should be displayed depending on that keyword.我有一个场景,我将在 vf 页面上显示输入文本字段,当我输入一些值并单击搜索按钮时,应根据该关键字显示真实帐户。 I have tried the following code,but i am unable to resolve the error Unknown property 'VisualforceArrayList.Name' The below is my code: class:
我尝试了以下代码,但无法解决错误Unknown property 'VisualforceArrayList.Name'以下是我的代码:class:
public class AccountswithKeywordfrompage {
public string keyword{get;set;}
public List<List<Account>> accountlist{get;set;}
public void Accounts(){
keyword = System.currentPageReference().getParameters().get('search');
accountlist=[FIND '+keyword' IN ALL FIELDS
RETURNING Account(Name)];
}
}
vf page: vf 页面:
<apex:page controller="AccountswithKeywordfrompage" standardStylesheets="false"> <apex:page controller="AccountswithKeywordfrompage" standardStylesheets="false">
<apex:form>
<apex:inputText label="SearchAccounts" id="search">
<apex:commandButton value="search" action="{!Accounts}"/>
</apex:inputText>
<apex:pageblock>
<apex:pageblockTable value="{!accountlist}" var="accountobj">
<apex:outputlink value="{!accountobj.Name}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Can anyone help me to solve the issue?谁能帮我解决这个问题?
accountlist
is a List<List<Account>>
, which is the wrong type; accountlist
是List<List<Account>>
,这是错误的类型; a SOSL search returns a List<List<sObject>>
. SOSL 搜索返回
List<List<sObject>>
。 It just so happens that your SOSL search only returns Account results.碰巧您的 SOSL 搜索只返回帐户结果。
When you iterate over a List<List<sObject>>
:当您遍历
List<List<sObject>>
时:
<apex:pageblockTable value="{!accountlist}" var="accountobj">
the type of the iteration variable is List<Account>
, which has no Name
property.迭代变量的类型是
List<Account>
,它没有Name
属性。
The cleanest solution is to declare your variable as a List<Account>
and extract the first element of the returned List<List<sObject>>
from SOSL.最干净的解决方案是将变量声明为
List<Account>
并从 SOSL 中提取返回的List<List<sObject>>
的第一个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.