Apex Code:
public class DynamicSOSLExample {
public static List<List<SObject>> searchContact(String searchField) {
List<List<SObject>> lstObjResults = new List<List<SObject>>();
String searchQuery ='FIND \'' + searchField+ '\' IN ALL FIELDS RETURNING Contact(FirstName,LastName)';
lstObjResults = search.query(searchQuery);
system.debug('List of Contacts:'+lstObjResults);
return lstObjResults;
}
}
Output: Run the following line in Execute anonymous window.
DynamicSOSLExample.searchContact('Smith');
public class DynamicSOSLExample {
public static List<List<SObject>> searchContact(String searchField) {
List<List<SObject>> lstObjResults = new List<List<SObject>>();
String searchQuery ='FIND \'' + searchField+ '\' IN ALL FIELDS RETURNING Contact(FirstName,LastName)';
lstObjResults = search.query(searchQuery);
system.debug('List of Contacts:'+lstObjResults);
return lstObjResults;
}
}
Output: Run the following line in Execute anonymous window.
DynamicSOSLExample.searchContact('Smith');
No comments:
Post a Comment