+ Start a Discussion
farah sheriffarah sherif 

need to correct this class

Note : it requires SOSL
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 method must accept an incoming string as a parameter
The method should then find any contact or lead that matches the string as part of either the first or last name
The method should finally use a return type of List<List< SObject>>


below is my code
public class ContactAndLeadSearch {
    
    public static List<List< SObject>> searchContactsAndLeads(String x){
        
        List<List<sObject>> searchList = [FIND {x} IN ALL FIELDS 
                   RETURNING Lead(FirstName,LastName),Contact(FirstName,LastName,Department)];
        
        return searchList;
    }
}
Best Answer chosen by farah sherif
Sitanshu TripathiSitanshu Tripathi
public class ContactAndLeadSearch {
    public static List<List<sObject>> searchContactsAndLeads(String lastName) {
        List<List<sObject>> searchList = [FIND :lastName IN NAME FIELDS 
                   RETURNING Contact(Name),Lead(FirstName)];
        System.debug(searchList);
        return searchList;
      }
}

If you get the 500 Point on your trail then please mark as a best answer. Don't forget Farah

All Answers

Sitanshu TripathiSitanshu Tripathi
public class ContactAndLeadSearch {
    public static List<List<sObject>> searchContactsAndLeads(String lastName) {
        List<List<sObject>> searchList = [FIND :lastName IN NAME FIELDS 
                   RETURNING Contact(Name),Lead(FirstName)];
        System.debug(searchList);
        return searchList;
      }
}

If you get the 500 Point on your trail then please mark as a best answer. Don't forget Farah
This was selected as the best answer
farah sheriffarah sherif
Done Sitanshu :)
Sitanshu TripathiSitanshu Tripathi
It's my pleasure #Farah