-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathWrite SOSL Queries
24 lines (18 loc) · 1.14 KB
/
Write SOSL Queries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Challenge 6:
Create an Apex class that returns both contacts and leads based on a parameter.
To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.
The Apex class must be called ContactAndLeadSearch and be in the public scope
The Apex class must have a public static method called searchContactsAndLeads
The method must accept an incoming string as a parameter
The method should then find any contact or lead that matches the string as part of either the first or last name
The method should finally use a return type of List<List< SObject>>
NOTE: Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name Smith. The challenge uses these records for the SOSL search
Solution:
public class ContactAndLeadSearch {
public static List<List<sObject>> searchContactsAndLeads(String lName){
List<list<sObject>> sList = [FIND :lName IN NAME FIELDS
RETURNING Contact(Name),Lead(FirstName)];
System.debug(sList);
return sList;
}
}