Hi Unnamalai Subramanian, 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.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
You can also try workbanch.https://workbench.developerforce.com/login.phpTo Execute Annonymous code like below :-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);
}
Above code is working fine for me.Please mark this as Best Answer if this will help you.ThanksAmit Chaudhary
4 respuestas