1

I'm a newbie to apex and am having issues completing the challenge on Trailhead. Can someone assist?

Create an Apex class that returns both contacts and leads based on a parameter.

  • With SOSL you can search against different object types that may have similar data, such as contacts and leads. To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.
  • The Apex class must be called ContactAndLeadSearch and be in the public scope.
  • The Apex class must have a public static method called searchContactsAndLeads.
  • The return type for searchContactsAndLeads must be List<List<SObject>> The searchContactsAndLeads method must accept an incoming string as a parameter, find any contact or lead that matches the string as part of either the first or last name and then return those records.

Here is my code:

public class ContactAndLeadSearch {
    public static List<List<SObject>> searchContactsAndLeads(String Name) {
        List<List<sObject>> searchList = [FIND 'Name' IN ALL FIELDS 
                                          RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];
    }
    Lead[] searchLeads = (Lead[])searchList[0];
    Contact[] searchContacts = (Contact[])searchList[1];
}

closed as off-topic by Eric, crmprogdev, cropredy, Ratan Paul, Chris Duncombe Dec 20 '15 at 12:28

  • This question does not appear to be about Salesforce within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I found the solution to this. It's: public class ContactAndLeadSearch { public static List<List<SObject>> searchContactsAndLeads(String name) { List<List<SObject>> result= [FIND :name IN ALL FIELDS RETURNING Contact(LastName), Lead(LastName)]; return result; } } – Jen Dec 29 '14 at 0:22
  • If you've solved your own question do please post (and accept) it as an answer. That can help others in the future. Though in the case of trailhead, considering that the goal is for everyone to solve the challenges and learn rather than google solutions (and find this one). Maybe it's best to remove the question ? Up to you. – Samuel De Rycke Feb 27 '15 at 8:45
  • 4
    User found answer and posted as comment. Voting to close question – Eric Dec 19 '15 at 15:51
  • Further, solutions to Trailhead questions per SF.SE guidelines are not to be posted in this forum, instead only tips, hints and guidance for how to reach a solution. – crmprogdev Dec 19 '15 at 16:21
0
public class ContactAndLeadSearch{
    public static List<List<Sobject>> searchContactsAndLeads(string Smith){

     List<List<Sobject>> contactsandleadsrecords =[find 'Smith' in all fields RETURNING contact(firstname,lastname),lead(firstname,lastname)];
     return contactsandleadsrecords ;
    }
}
0
public class ContactAndLeadSearch {

    public static list<list<sobject>> searchContactsAndLeads(String name){

        list<list<sobject>> result = [FIND :name IN ALL FIELDS RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];

        return result;
    }
}

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