Here is my code below:
public class ContactAndLeadSearch {
public static List<List<SObject>>ContactAndLeadSearch(String s1){
List<List<sObject>> searchList = [FIND 's1' IN ALL FIELDS
RETURNING Lead(FirstName,LastName),Contact(FirstName,LastName)];
Lead[] searchLeads = (Lead[])searchList[0];
Contact[] searchContacts = (Contact[])searchList[1];
System.debug('Found the following leads.');
for (Lead a : searchLeads) {
System.debug(a.Name);
}
System.debug('Found the following contacts.');
for (Contact c : searchContacts) {
System.debug(c.LastName + ', ' + c.FirstName);
}
return searchList;
}
}
Please check below post for solution. I hope that will help uhttps://developer.salesforce.com/forums/?id=906F0000000BO5rIAG Public 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;
}
}
Execute below code in In Debug Annonymous window
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 let us know if this will help u