2

Hi I'm doing the challenge for SOSL Queries and here is what I have accomplished so far.

public class ContactAndLeadSearch {
    public static List < List < SObject >> searchList(String toFind) {
        List < List < SObject >> result = [FIND: toFind IN ALL FIELDS
            RETURNING Contact(FirstName, LastName), Lead(FirstName, LastName)
        ];
        return result;
    }
}

When I check the challenge I get an error of

Executing the 'searchContactsAndLeads' method failed. Either the method does not exist, is not static, or does not return the expected search results.

I am not sure what I'm missing with my fragment of code.

1
  • 1
    You have a method name of searchList and the error says a method name of searchContactsAndLeads is what is expected.
    – Keith C
    May 27 '16 at 9:36
1

This has been answered by @KeithC here is the updated code:

public class ContactAndLeadSearch {
 public static List<List<SObject>> searchContactsAndLeads (String toFind) {
    List<List<SObject>> result = [FIND :toFind IN ALL FIELDS 
                        RETURNING Contact(FirstName,LastName), Lead(FirstName,LastName)];
    return result;
 } 
}
0
0
public class ContactAndLeadSearch {

public static List<List<SObject>> searchContactsAndLeads (String searchstr)
{
//we need to first search for any records with the string assigned to searchstr 
//Then from the above list, we need to filter out records having the searchstr in either the FirstName or LastName
    List<List<SObject>> result = [FIND :searchstr IN ALL FIELDS 
                    RETURNING Contact(FirstName,LastName where FirstName =:searchstr or LastName =:searchstr),
                              Lead(FirstName,LastName where FirstName =:searchstr or LastName =:searchstr)];
    return result;
  } 
 }
1
  • 1
    Welcome to SFSE, Please go through How to Answer section to understand what is the best way to answer. You should always explain what is the issue with original question and how your answer fix that.
    – Himanshu
    Aug 12 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.