01
JulMonth End Offerl : Get 30% OFF + $999 Study Material FREE - SCHEDULE CALL
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.
Learn Salesforce in the Easiest Way

Read: Advance Your Career by Imbibing the Skills with Salesforce Certification
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.
Salesforce Training For Administrators & Developers

List> accountSearchList =newList
>(); accountSearchList=[FIND {Joe Smith}IN Name Fields RETURNING lead (name, phone Where createddate = THIS_FISCAL_QUARTERLIMIT 20) ]; list
accs; accs=(list )result[0]; system.debug(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..')); return; } } else{ apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least three characters..')); return; } } } 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:facet> </apex:actionStatus> </apex:form> <apex:outputPanel title="" id="error"> <apex:pageMessages ></apex:pageMessages> </apex:outputPanel> <apex:pageBlock title="Accounts" id="acct"> <apex:pageblockTable value="{!accList }" var="acc"> <apex:column value="{!acc.name}"/> <apex:column value="{!acc.Type}"/> </apex:pageblockTable> </apex:pageBlock> <apex:pageBlock title="Contacts" id="cont"> <apex:pageblockTable value="{!conList}" var="con"> <apex:column value="{!con.name}"/> <apex:column value="{!con.email}"/> </apex:pageblockTable> </apex:pageBlock> <apex:pageBlock title="Opportunities" id="oppt"> <apex:pageblockTable value="{!optyList}" var="opty"> <apex:column value="{!opty.name}"/> <apex:column value="{!opty.StageName}"/> </apex:pageblockTable> </apex:pageBlock> </apex:page>
Output
Read: What are Salesforce Objects? Top 4 Salesforce Standard Objects

Salesforce Training For Administrators & Developers

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: A Comprehensive Salesforce Tutorial For Experienced & Beginners
Pinterest
Email
The JanBask Training Team includes certified professionals and expert writers dedicated to helping learners navigate their career journeys in QA, Cybersecurity, Salesforce, and more. Each article is carefully researched and reviewed to ensure quality and relevance.
Cyber Security
Data Science
QA
Salesforce Service Cloud
AWS
Search Posts
Related Posts
Best Salesforce Certifications to Consider in 2025 : Level Up Your Salesforce Expertise
244.5k
Salesforce Business Analyst Salary: How Much Can You Earn?
2.8k
What is the Salesforce AppExchange? Packages Installation Guide
234.2k
Salesforce Certifications Paths- What does the Future hold for Salesforce?
464.8k
Top 12 Salesforce APP Builder Interview Questions and Answers 2018
166.8k
Receive Latest Materials and Offers on Salesforce Course
Interviews