You need to sign in to do that
Don't have an account?
bujji
Error in SOSL
Hi,
I am trying small query but i am getting error while try to display.
ERROR-- line 4, column 59: Initial term of field expression must be a concrete SObject: LIST
String searchTerm = 'abc';
List<List<Account>> accs =[FIND:searchTerm RETURNING Account(Id,Name)];
for(List<Account> a: accs){
system.debug('**************SOSL Result*****************'+a.Name);
}
I want to see the account name.
Thanks,
Bujji
Your for list iterator variable is a list of accounts, so you need to iterate those:
All Answers
Your for list iterator variable is a list of accounts, so you need to iterate those:
Hi bujji,
Bob is exactly right.
The error is in the followed line
here "a" refer to List<Account> type not simply Account.
So a.Name is invalid and it means to (List<Account>).Name which is invalid syntax.
The followed will give you the first Account Name from the list.
You can refer Bob's Comment in order to Iterate through all the Accounts retrieved.
Thanks
Hi All,
Can you please try like below.
Explanation : SOSL query will return only 'sObjects' not actual objects. So we need to convert the 'sObject' to actual object 'account' then we can use as like account. I just tryied.
Please let me know If I am wrong.
=============================================================
String searchTerm = 'acc';
List<List<Sobject>> accs =[FIND:searchTerm RETURNING Account(Id,Name)];
for(SObject acc : accs[0]){
Account a = (Account)acc;
system.debug('**************SOSL Result*****************'+a.Name);
}
================================================================