0

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. I have tried the following code ,but i am unable to resolve the error Unknown property 'VisualforceArrayList.Name' The below is my code: 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:

<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 ?

m.dinesh
  • 1
  • 3

1 Answers1

0

accountlist is a List<List<Account>>, which is the wrong type; a SOSL search returns a List<List<sObject>>. It just so happens that your SOSL search only returns Account results.

When you iterate over a List<List<sObject>>:

<apex:pageblockTable value="{!accountlist}" var="accountobj">

the type of the iteration variable is List<Account>, which has no Name property.

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.

David Reed
  • 2,522
  • 2
  • 16
  • 16
  • When i replace the things that you said still i am getting some error like Unknown property 'AccountswithKeywordfrompage.list' And can you please explain me how to get the list vallues that are returned from controller class to vf page – m.dinesh Feb 17 '21 at 09:05