function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KavyaKavya 

VF ERROR

Hi ,

 

I was using this particular code snippet specified below and it threw me an error (highlighted in red).. and I would also like that this code snippet works fine with other Standard and custom objects but  not for Account......can some please help me out by educating me as to why this kind of an error occurs.

 

 

public with sharing class LookupPopupController
{
 public String query {get; set;}
 public List<Account> accounts {get; set;}
 
 public PageReference runQuery()
 {
  List<List<Account>> searchResults=[FIND :query IN ALL FIELDS RETURNING Account (id, name, billingstreet, billingcity, billingpostalcode)];
  accounts=searchResults[0];
    return null;
 }
}

 

 

Compile Error: Illegal assignment from LIST<LIST<SObject>> to LIST<LIST<Account>>

bob_buzzardbob_buzzard

SOSL returns a list of sobject lists, but you have told the compiler that it is returning a list of account lists.

 

Its better practice to leave it returning the sobjects and cast the result when you assign to your account list.  E.g.

 

List<List<sobject>> searchResults=[FIND :query IN ALL FIELDS RETURNING Account (id, name, billingstreet, billingcity, billingpostalcode)];
accounts=(List<Account>) searchResults[0];