What Is SOSL?
By the end of this lesson, you'll be able to:
- Explain what SOSL is and how it differs from SOQL
- Recognize the kind of problem SOSL is built to solve
- Identify when to reach for SOSL instead of SOQL
Prerequisites: Module 20: "SOQL"
The problem SOQL can't solve well
Imagine a support agent needs to find anything related to "Riverbend Farms" — it could be an Account, a Contact, a Case, or a Lead. With SOQL, this means writing and running a separate query per object: one for Account, one for Contact, one for Case, one for Lead — four queries, and a fifth object added later means a fifth query.
What SOSL does instead
FIND {Riverbend Farms} IN ALL FIELDS RETURNING Account, Contact, Case, Lead
One SOSL statement searches across every named object simultaneously, matching the search text against multiple text fields at once — a single search, multiple object types, in one round trip.
SOQL vs SOSL, side by side
| SOQL | SOSL | |
|---|---|---|
| Searches | One object at a time | Multiple objects at once |
| Best for | Precise, structured filtering (WHERE Industry = 'Technology') |
Free-text search across many fields/objects |
| Fields searched | Exactly the ones you name | Text fields marked as searchable |
Neither replaces the other — SOQL remains the default for "give me these specific records," and SOSL is reached for specifically when the search spans multiple object types or the exact object isn't known in advance.
Exercise
As a comment, explain why searching for "Acme" across Accounts, Contacts, and Leads would be awkward with SOQL alone.
Show hint
Think about how many separate queries that would take.
What Is SOSL? Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
SOSL (Salesforce Object Search Language) searches text across multiple objects at once — where SOQL asks "give me records from this one object matching this condition," SOSL asks "find anything, anywhere, matching this text."