With SOSL you can search against different object types that may have similar data, such as contacts and leads.create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter
Use the Salesforce Object Search Language (SOSL) to search your organization’s Salesforce data for specific information. WithSOSL, you can search all objects—including custom objects—that you have access to in a single query. SOSL allows you to specify the following for source objects: -text expression -scope of fields to search -list of objects and fields to retrieve -conditions for selecting rows in the source objects https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_about.htm
Please try below code. I hope that will help you
public class ContactAndLeadSearch{
public static List<List< SObject>> searchContactsAndLeads(String first)
{
List<List<sObject>> searchList=[FIND 'Smith' IN ALL FIELDS RETURNING Lead(FirstName,LastName),Contact(FirstName,LastName)];
return searchList;
}
}
Use the Salesforce Object Search Language (SOSL) to search your organization’s Salesforce data for specific information. WithSOSL, you can search all objects—including custom objects—that you have access to in a single query. SOSL allows you to specify the following for source objects: -text expression -scope of fields to search -list of objects and fields to retrieve -conditions for selecting rows in the source objects https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_about.htm
Please try below code. I hope that will help you
public class ContactAndLeadSearch{
public static List<List< SObject>> searchContactsAndLeads(String first)
{
List<List<sObject>> searchList=[FIND 'Smith' IN ALL FIELDS RETURNING Lead(FirstName,LastName),Contact(FirstName,LastName)];
return searchList;
}
}
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads (String s) {
List<List<SObject>> searchlist=[FIND 'Smith' IN ALL FIELDS
RETURNING Contact(FirstName,
LastName WHERE (FirstName =:s
OR LastName =:s)),
Lead(FirstName,LastName
WHERE (FirstName =:s
OR LastName =:s))];
return searchList;
}
}
SOSL allows you to specify the following for source objects:
-text expression
-scope of fields to search
-list of objects and fields to retrieve
-conditions for selecting rows in the source objects
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_about.htm
Please try below code. I hope that will help you Please let us know if this will help you
Thanks
Amit Chaudhary
All Answers
SOSL allows you to specify the following for source objects:
-text expression
-scope of fields to search
-list of objects and fields to retrieve
-conditions for selecting rows in the source objects
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_about.htm
Please try below code. I hope that will help you Please let us know if this will help you
Thanks
Amit Chaudhary