Skip to content

Instantly share code, notes, and snippets.

@ganmahmud
Last active November 21, 2018 06:48
Show Gist options
  • Select an option

  • Save ganmahmud/ad2d2ce9a6be71c1a91b2ba0a42ea7bc to your computer and use it in GitHub Desktop.

Select an option

Save ganmahmud/ad2d2ce9a6be71c1a91b2ba0a42ea7bc to your computer and use it in GitHub Desktop.
Create an Apex class that returns both contacts and leads based on a parameter.
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads(String lastName){
List<List<SObject>> searchList = [FIND :lastName IN ALL FIELDS
RETURNING Lead(Name), Contact(FirstName,LastName)];
Lead[] searchLead = (Lead[])searchList[0];
Contact[] searchContacts = (Contact[])searchList[1];
System.debug('Found the following leads.');
for (Lead a : searchLead) {
System.debug(a.Name);
}
System.debug('Found the following contacts.');
for (Contact c : searchContacts) {
System.debug(c.LastName + ', ' + c.FirstName);
}
return searchList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment