Difference between SOQL and SOSL

by | Aug 2, 2021 | Salesforce

What is SOQL

Salesforce Object Query Language is used to fetch data from the salesforce database. SOQL searches the records using a perfect match of given criteria and the operation can be performed on a single salesforce object only.

What is SOSL

Salesforce Object Search Language is also used to fetch the data from the salesforce database. 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.

Difference between SOQL and SOSL (In tabular format)

There are many differences to be discussed but let’s go with the important ones here:

SOQL

(Salesforce Object Query Language)

SOSL

(Salesforce Object Search Language)

What’s returned are Records.What’s returned are Fields.
Searching will be limited to one sObject.Searching can be done in all the sObjects.
It doesn’t search beyond the object.It searches the entire organization.
We can query multiple objects when they are related objects.We can query multiple objects even though they are not related objects.
We can query using all fields.We can query using only email, text or phone fields only.
SOQL is suitable for use in classes and triggers.SOSL is not suitable for use in classes and triggers.
DML operations can be are performed on the retrieved records.DML operations cannot be performed on the retrieved records.
The keyword used is “SELECT”.The keyword used us “FIND”.
Example:

SELECT Id, Name FROM Account WHERE Name = ‘Acme’

Example:

FIND {Joe Smith} IN Name Fields RETURNING lead(name, phone)

 

Author

0 Comments

Submit a Comment

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.