Salesforce Object Search Language


SOSL is a language used to retrieve the data from the Salesforce database in a unique way. Using this language we can do some advanced fetching from the database. This language is used by developers when they need to do a search based on a single word or phrase. In this article we will learn more about Salesforce Object Search Language.

What is SOSL

SOSL is a Salesforce Object Search Language used to query the database using texts in the records data. Read this carefully, “It actually searches for the text we give and fetches the data from the records where the given text matches any data from the salesforce”.

When to Use SOSL

That’s simple, when you want to retrieve some data based on the keywords that can be in any field and you get the results from your desired objects and fields.

You can also use this in the query editor and find all the results in the “search results” and can have fun.

Significance of SOSL

There is a lot of importance of using SOQL

  • You can easily fetch the data by using a simple word or phrase as per your requirement.
  • You can use “IN” and “RETURNING” keywords to customize the results in a deep way.
  • You can search only in specifies fields using the “IN” keywords and get data of only specified fields using the “RETURNING” keyword.

SOSL Syntax

Well, the syntax is of two types based on the location you write it.

  • We use this syntax when we write it in apex code:
    FIND ‘word or phrase’ IN (fields you want to search) RETURNING (Objects and fields you want to fetch)


  • We use this syntac when we write it in Query Editor:
    FIND {word or phrase} IN (fields you want to search) RETURNING (Objects and fields you want to fetch)


  • This is an example of writing in apex code.
    List<SObject> searchList = [FIND 'SFDC' IN ALL FIELDS RETURNING Account(Name)];

This example searches all the fields for the word and only returns the Name fields from the Account objects and stores that in variable “searchList” which is of type List.


  • This is an example of writing in Query Editor.


This example searches the same as the above example and populates the data in the “Search Results” in the Query Editor itself.


  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.