Key Differences Between SOQL and SOSL
Key Differences Between SOQL and SOSL
Feature |
SOQL (Salesforce Object Query Language) |
SOSL (Salesforce Object Search Language) |
Purpose |
Retrieves records
from a single object or related objects. |
Searches for text
across multiple objects and fields. |
Use Case |
Use when you know the
object and fields you want to query. |
Use when you don't know
where the data is (full-text search). |
Scope |
Works on one
object at a time (or related objects via relationships). |
Searches multiple
objects at once. |
Search Type |
Structured query-based
search. |
Full-text keyword-based
search. |
Works With |
Standard/Custom
objects, Fields (SELECT queries). |
Indexed text
fields, Name fields, Email fields. |
Syntax Example |
SELECT Name, Email FROM Contact WHERE LastName =
'Smith' |
FIND 'Smith' IN ALL FIELDS RETURNING Contact(Name,
Email) |
Wildcards |
Supports LIKE '%text%' for
partial matches. |
Supports * and ? wildcards. |
Performance |
Faster when querying specific
objects and fields. |
Can be faster for searching
across multiple objects. |
Use in Apex |
Database.query('SELECT
Name FROM Account') |
Search.query('FIND {John}
IN Name Fields RETURNING Account(Name)') |
Comments
Post a Comment