You need to sign in to do that
Don't have an account?

error in sosl query
Hello friends
I have search page, I enter account name and it will fetch relevant fields
I have given code in Visual force page and apex class
<apex:page standardController="Account"
extensions="MySearch">
tabStyle="Account">
<apex:form>
<apex:inputText value="{!searchstring}"/>
<apex:commandButton value="{!SearchAccount}"
title="Account Search}"/>
<apex:pageBlock title="Account Info">
<apex:pageBlockTable value="{!accts}"
var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Type}"/>
<apex:column value="{!a.Industry}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class MySearch
{
list<Account> accts;
public String searchstring{get;set;}
public MySearch(ApexPages.StandardController controller)
{
}
public list<Account> getaccts()
{
return accts;
}
public PageReference SearchAccount()
{
accts = (list<Account>) [FIND :searchstring IN ALL FIELDS RETURNING Account(Name, Type, Industry)];
return null;
}
}
when I compile apex class I am getting an error as : "Compile Error: Incompatible types since an instance of List<List<SObject>> is never an instance of List<Account> at line 18 column 16
Please let me know how I can resolve this
thanks
sonali
I have search page, I enter account name and it will fetch relevant fields
I have given code in Visual force page and apex class
<apex:page standardController="Account"
extensions="MySearch">
tabStyle="Account">
<apex:form>
<apex:inputText value="{!searchstring}"/>
<apex:commandButton value="{!SearchAccount}"
title="Account Search}"/>
<apex:pageBlock title="Account Info">
<apex:pageBlockTable value="{!accts}"
var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Type}"/>
<apex:column value="{!a.Industry}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class MySearch
{
list<Account> accts;
public String searchstring{get;set;}
public MySearch(ApexPages.StandardController controller)
{
}
public list<Account> getaccts()
{
return accts;
}
public PageReference SearchAccount()
{
accts = (list<Account>) [FIND :searchstring IN ALL FIELDS RETURNING Account(Name, Type, Industry)];
return null;
}
}
when I compile apex class I am getting an error as : "Compile Error: Incompatible types since an instance of List<List<SObject>> is never an instance of List<Account> at line 18 column 16
Please let me know how I can resolve this
thanks
sonali
Le
All Answers
Because with SOSL, the return will be List<List<SObject>>. Basically, you can not cast this type into list<Account>.
Le
Since the SOSL query results in a list of lists. So each list contains an array of the returned records. So for that purpose you have to create a list of list of the Account and then assign the values in it.
Hence you can modify your code as below :-
<-----------controller----------> Thanks.
I modified the apex code as given by you. It compiles fine but the visual force page throws an error as "Error: Unknown property 'VisualforceArrayList.Name'.
<apex:page standardController="Account"
extensions="MySOSLSearch">
<apex:form>
<apex:inputText value="{!searchstring}"/>
<apex:commandButton action="{!SearchAccount}"
value="Account Search}"/>
<apex:pageBlock title="Account Info">
<apex:pageBlockTable value="{!accts}"
var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Type}"/>
<apex:column value="{!a.Industry}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please let me know
I modified the code as given by you works fine but VF page showing error as "Error: Unknown property 'VisualforceArrayList.Name'
could u pls let me know.
Thanks
sonali
Le
It works . Thanks
one more thing.
I need to have a custom popup which only display all account names. Then I will select the acocunt name and perform search criteria
could u just tell me how to go about if?
thanks
sonali verma
I have made custom popup on a custom object with the help of page reference. Which on preview shows the home page after which on button click it opens up new page along with your requriement for search criteria based on name and displays it to the home page once you select it. You can use it for your standard object with the reuired functionality.
<----------Controller-----------> <----------Page1--------> <--------Page2--------> Thanks