3
List <Lead> results ;
String searchText;

public PageReference doSearch (){
results = (List<lead>) [Find :searchText RETURNING Lead (Name, email)] [0];

In the line of results, when I set only the first row (as in [0]) of list, does that mean a single lead record from the SOSL?

If so, would this have worked if results was defined as a single record instead of a list varible? That is:

Lead results; 

1 Answer 1

5

When you do a SOSL search, it returns a List<List<SObject>>. If you're trying to get results for exactly one object type (Lead, for example), you might just want the one List<SObject> Since you're only RETURNING that type, you can just get the first element. A more verbose declaration would be:

List<List<SObject>> searchResults = [/*search*/];
List<Lead> leadResults = searchResults[0];
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .