PRIDE MONTH ALERT : FLAT 20% OFF On Our Best-Selling Courses Use -  PRIDE20

- Salesforce Blogs -

Salesforce Object Search Language (SOSL)


Use the Salesforce Object Search Language (SOSL) to construct text-based search queries against the search index. SOSL or Salesforce object query language searches for a particular string from multiple objects. It always returns a list object. The result lists are always returned in the same order as they were specified in the SOSL query. SOQL and SOQL in Salesforce are the most used language by developers.

SOSL (Salesforce Object Query Language) is similar to SOQL (Salesforce Object Query Language) but it can search for records from multiple Salesforce objects. We can search in numerous objects at the same time using SOSL. In SOQL, we can query only one object at a time but in SOSL, we can query multiple Salesforce objects together. To know more about Salesforce objects, you should study the Salesforce object model and how it works exactly. A salesforce object model helps you to map the data properly. Also, you can combine data logically as per the requirement.

Things to remember for Salesforce Object Search Language SOSL

  • SOSL statements cannot exceed 10,000 characters.
  • The SOSL query starts with the keyword ‘FIND’.
  • We can search for some specified string like ‘USGLOBAL’ in multiple Salesforce objects at the same time.
  • It searches records from the entire database. You can also combine SOQL and SOSL in Salesforce for more accurate search results.
  • The result of SOSL is a list of lists of sObjects “List<List<sObject>>”.
  • The returned result contains the list of sObjects in the same order as the order mentioned in the SOSL query.
  • If a SOSL query does not return any records for a specified sObject type, then search results include an empty list for that sObject.
  • The search string should be at least two characters long.
  • You can search text, email, and phone fields for multiple objects.
  • The maximum batch size is 2,000 records.
  • It can perform SOAP or REST calls
  • Apex statements are used for SOQL and SOSL in Salesforce.
  • Visualforce controllers and getter methods
  • Schema Explorer of the Eclipse Toolkit

Learn Salesforce in the Easiest Way

  • Learn from the videos
  • Learn anytime anywhere
  • Pocket-friendly mode of learning
  • Complimentary eBook available

Read: Top 12 Salesforce APP Builder Interview Questions and Answers 2018

When to Use SOSL (Salesforce Object Search Language)?

  • Use SOSL when you don’t know which object or in which field the data resides.
  • Retrieve data for a specific term that you know exists within a field. SOQL (Salesforce Object Query language) searches are faster and can return more relevant results.
  • It finds the search text efficiently from multiple objects whether they are related to each other or not.
  • Retrieve data that are in Chinese, Japanese, Korean, or Thai. Morphological tokenization for CJKT terms helps ensure accurate results.

Performance Considerations for Salesforce Object Search Language 

If your searches are too general, they are slow and return too many results. Use the following clauses to define efficient text searches. You can also use SOQL (Salesforce Object Query language) if needed.

  • IN: Limits the types of fields to search, including email, name, or phone.
  • LIMIT: Defines the maximum number of rows to return.
  • OFFSET: Displays the search results on multiple pages.
  • RETURNING: It will search from that particular object and fields that are mentioned and return the result.

Where can we use SOSL?

  • SOSL is used if we don’t know in which object the data is present. If you know about the object then you may prefer SOQL (Salesforce Object Query language) too.
  • We can retrieve multiple Salesforce objects and field values efficiently when the objects may or may not be related to each other.
  • We can search only in those fields whose data type is text, phone, and Email.
  • We can use SOSL in classes but not in Triggers.
  • We cannot perform DML operations on search results when using SOSL. At the same time, when using SOQL and SOSL in Salesforce, we can perform DML operations too.

Salesforce Training For Administrators & Developers

  • No cost for a Demo Class
  • Industry Expert as your Trainer
  • Available as per your schedule
  • Customer Support Available

Syntax of Salesforce Object Search Language

List> accountSearchList =newList>();
accountSearchList=[FIND {Joe Smith}IN Name Fields RETURNING 
lead (name, phone Where createddate = THIS_FISCAL_QUARTERLIMIT 20) ];
 list accs;
Example of SOSL
Apex class
Public with sharing class SOSLdemoExample{
 Public List optyList {get;set;}
 Public List conList{get;set;}
 Public List accList{get;set;}
 Public String searchStr{get;set;}
   Public SOSLdemoExample(){
  Public void soslSearchmethod (){
   optyList = New List();
   conList = New List();
   accList = New List();
   if(searchStr.length() > 2){
   String searchStr1 = '*'+searchStr+'*';
   String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING  Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName)';
   List> searchList = search.query(searchQuery);
   accList = ((List)searchList[0]);
   conList  = ((List)searchList[1]);
   optyList = ((List)searchList[2]);
   if(accList.size() == 0 && conList.size() == 0 && optyList.size() == 0){
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
   apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least three characters..'));
Visualforce Page
<apex:page controller="SOSLdemoExample">
<apex:form >
<apex:inputText value="{!searchStr}"/>
<apex:commandButton value="Search in Account, Contact, Opportunity" action="{!soslSearchmethod }" reRender="acct,error,oppt,cont" status="actStatusId"/>
<apex:actionStatus id="actStatusId">
<apex:facet name="start" >
<img src="/img/loading.gif"/>
<apex:outputPanel title="" id="error">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock title="Accounts" id="acct">
<apex:pageblockTable value="{!accList }" var="acc">
<apex:column value="{!}"/>
<apex:column value="{!acc.Type}"/>
<apex:pageBlock title="Contacts" id="cont">
<apex:pageblockTable value="{!conList}" var="con">
<apex:column value="{!}"/>
<apex:column value="{!}"/>
<apex:pageBlock title="Opportunities" id="oppt">
<apex:pageblockTable value="{!optyList}" var="opty">
<apex:column value="{!}"/>
<apex:column value="{!opty.StageName}"/>


Read: Know Everything About a Salesforce Consultant Roles and Responsibilities!

Salesforce Object Search Language (SOSL)

Salesforce Training For Administrators & Developers

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Final Words

SOQL and SOSL in Salesforce are two popular languages to manage Salesforce objects, Standard objects and custom objects. Also, it is easy to retrieve data with the help of these two-programming languages. It may be tough learning about the syntax of the language and the Salesforce object model but the constant effort and dedication can make things easier than expectations. All the Best!

Read: How To Create a Custom Object TABS In Salesforce.Com?


Salesforce Tutorial Overview

FaceBook Twitter Google+ LinkedIn Pinterest Email

    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


Trending Courses


  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

1 day 02 Jul 2022


  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

0 day 01 Jul 2022

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

7 days 08 Jul 2022


  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

7 days 08 Jul 2022


  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

0 day 01 Jul 2022


  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

7 days 08 Jul 2022

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

7 days 08 Jul 2022

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

0 day 01 Jul 2022


  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

1 day 02 Jul 2022

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

15 days 16 Jul 2022

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

28 days 29 Jul 2022


  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

0 day 01 Jul 2022

Search Posts


Trending Posts

Receive Latest Materials and Offers on Salesforce Course