0% found this document useful (0 votes)
33 views6 pages

Salesforce Developer Training in Chandigarh

Salesforce Developer Training in Chandigarh - www.gberp.com

Uploaded by

Kartik Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

Salesforce Developer Training in Chandigarh

Salesforce Developer Training in Chandigarh - www.gberp.com

Uploaded by

Kartik Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ananaya-SOSL - SOQL

Thursday, September 05, 2024 11:06 AM

Salesforce Object Search Language (SOSL) is a powerful search language in


Salesforce that allows you to search for text across multiple objects and fields in
Salesforce. Unlike SOQL (Salesforce Object Query Language), which is used to
retrieve records from a single object, SOSL can search text, emails, and other
fields across multiple objects in a single query.

Basic Structure of an SOSL Query


An SOSL query looks for specific keywords in records across one or more objects.
Here’s a simplified structure:

FIND 'searchString' IN SCOPE FIELDS RETURNING ObjectType(FieldList WHERE


condition LIMIT n)

sforce Page 1
Screen clipping taken: 05-Sep-24 11:22 AM

Screen clipping taken: 05-Sep-24 11:25 AM

sforce Page 2
• FIND 'John': Searches for the keyword 'John'.
• IN ALL FIELDS: Searches in all text fields of the objects.
• RETURNING:
• Lead (Id, FirstName, LastName, Company): Specifies that you want to retrieve
Lead records and display the Id, FirstName, LastName, and Company fields.
• Contact (Id, FirstName, LastName, Email): Specifies that you want to retrieve
Contact records and display the Id, FirstName, LastName, and Email fields.
• Result Type: The query returns a list of lists. Each list contains the search results
for a specific object. In this case, the first list contains Lead results, and the
second list contains Contact results.

List<Lead> leads = (List<Lead>)searchResults[0]; // First list contains Lead results


List<Contact> contacts = (List<Contact>)searchResults[1]; // Second list contains
Contact results
searchResults
Lead
Contact
searchResults[0]
searchResults[1]

The searchResults variable stores the results of the SOSL query. It is a list of lists
(List<List<SObject>>), where each inner list contains records of a specific object
type.
searchResults[0]: The first list in searchResults contains the Lead records found by
the SOSL query.
This list is cast to a List<Lead> type and stored in the leads variable.

searchResults[1]: The second list in searchResults contains the Contact records


found by the SOSL query.
sforce Page 3
found by the SOSL query.
This list is cast to a List<Contact> type and stored in the contacts variable.

Screen clipping taken: 05-Sep-24 11:47 AM

The System.debug() method is used to print the leads and contacts lists to the
Salesforce Developer Console. This helps you see what records were found.

Screen clipping taken: 05-Sep-24 11:51 AM

sforce Page 4
Screen clipping taken: 05-Sep-24 11:55 AM

sforce Page 5
Screen clipping taken: 05-Sep-24 11:55 AM

sforce Page 6

You might also like