Last active
November 21, 2018 06:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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