Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
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; } }
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); }
Execute below code in In Debug Annonymous window
Refer to the following link for details description.
Please mark it as the best answer if you find it useful.
Thanks,
Anuj.
To Help us in return, Please select it as a best answer and like it after that.
Thanks,
Anuj.
public class ContactAndLeadSearch {
public static List<List<sObject>> searchContactsAndLeads(String searchTerm){
List<List<sObject>> contactsAndLeads = [FIND :searchTerm IN ALL FIELDS
RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];
System.debug(contactsAndLeads);
return contactsAndLeads;
}
}
// Remember then to access static methods by class name, not object name
e.g. from execute anomonous:
ContactAndLeadSearch.searchContactsAndLeads('Smith');