
The Apex class must be called 'ContactAndLeadSearch' and be in the public scope.
The Apex class must have a public static method called 'searchContactsAndLeads'.
Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name 'Smith'. The challenge uses these records for the SOSL search.
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.
Error received: Challenge not yet complete... here's what's wrong:
Executing the 'searchContactsAndLeads' method failed. Either the method does not exist, is not static, or does not return the expected search results.
Here is my code:public class ContactAndLeadSearch{
public static List<List< SObject>> searchContactsAndLead(String name)
{
List<List<sObject>> result=[FIND :name IN ALL FIELDS RETURNING Lead(LastName),Contact(LastName)];
return result;
}
}PLEASE ADVISE...Thanks Community!!!
Please try below class:-
NOTE:- if you want to search same keyword in mutliple field then dnt add where you can try IN ALL FIELDS.Execute below code in In Debug Annonymous windowPublic Class ContactAndLeadSearch
{
Public static List<List<sObject>> searchContactsAndLeads(String searchword)
{
String searchQuery = 'FIND \'' + searchword + '\' IN ALL FIELDS RETURNING Lead(Name,FirstName,LastName ), Contact(FirstName,LastName )';
List<List<sObject>> searchConLead = search.query(searchQuery);
return searchConLead;
}
}
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('amit');
List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();
leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);
for(Lead a:leadList)
{
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
Please check below post
https://developer.salesforce.com/forums/?id=906F0000000BO5rIAGPlease let us know if this will help youThanksAmit Chaudhary