← Back to list

Mastering SOSL(Google BUT Salesforce Style) Basics for PD1

🎯 This deep-dive covers core SOSL concepts tested in the Platform Developer I exam(Of which I completed on 12-Aug-2025).

Musa Ndlala · 2025-08-12 05:20 · 2 claps · 3.0 min read paywalled
#salesforce #sosl #pd1 #apex #salesforceklever
Open on Medium ↗
Wiki topics: CRM · Email & CRM 👗 · Fashion

Mastering SOSL(Google BUT Salesforce Style) Basics for PD1

🎯 This deep-dive covers core SOSL concepts tested in the Platform Developer I exam(Of which I completed on 12-Aug-2025).

💭 There Comes a Moment in Every Salesforce Dev’s Journey… …when you stop just writing SOQL queries and start wondering:

“How do I search across multiple objects fast, with wildcards, fuzzy matches, and text fields all at once?”

Welcome to SOSL — Salesforce’s full-text, multi-object search engine. Think of it as google but Salesforce Style.

🧠 My Learning Strategy: Stay Curious, Stay Sharp

✅ What Is SOSL? ⏰ When Would You Use SOSL? 🌍 Where Would You Use SOSL in Salesforce? ❓Why Would You Use SOSL? 🛠 How Would You Use SOSL?

✅ What Is SOSL?

SOSL (Salesforce Object Search Language) is the full-text search language inside Salesforce. Unlike SOQL, which queries one object at a time with filters, SOSL lets you:

  • Search multiple objects simultaneously.
  • Search text across multiple fields in those objects.
  • Use wildcards (*) and fuzzy matching (~) to find close or partial matches.

Think of it like the Google search bar for your Salesforce org’s data.

⏰ When Would You Use SOSL?

  • You want to find a keyword (like a name, email, or phone number) across Accounts, Contacts, Leads all at once.
  • You need a quick, broad search experience in your app or UI.
  • Your search text might be partial or misspelled, requiring flexible matching.

🌍 Where Would You Use SOSL in Salesforce?

  • In Apex classes or triggers to find related records quickly.
  • In Visualforce or Lightning components that provide search interfaces.
  • Anywhere you want to replicate a Google-like search inside your Salesforce org.

❓ Why Would You Use SOSL?

  • It’s faster than running many SOQL queries on different objects.
  • It supports wildcards and fuzzy matching out-of-the-box.
  • Salesforce automatically indexes searchable text fields to speed up full-text searches.

🛠 How Would You Use SOSL?

Here’s the SOSL toolbox, with examples showing core features and limits:

1. Searching Multiple Objects at Once

Calling in Apex

List<List<sObject>> searchList =[FIND 'Musa' IN ALL FIELDSRETURNING 
Account(Id, Name)    , 
Contact(Id, FirstName, LastName)    , 
Lead(Email)];

Calling in query Editor

FIND {Musa} IN ALL FIELDS
RETURNING Account(Id, Name), Contact(Id, FirstName, LastName), Lead(Email)

Searches for “Musa” in all searchable fields of these objects.

2. Using the IN Clause to Limit Search Scope

Calling in query Editor

FIND {Mu} IN NAME FIELDS
RETURNING Contact(Id, FirstName, LastName)

Calling in Apex

List<List<sObject>> searchList =[FIND {Mu} IN NAME FIELDS
RETURNING Contact(Id, FirstName, LastName)];

Restricts search to only name fields — faster and more focused.

3. Using Wildcards for Partial Matches

Calling in query Editor

FIND {Mu*} IN ALL FIELDS
RETURNING Contact(Id, FirstName, LastName)

Calling in Apex

List<List<sObject>> searchList = [FIND {Mu*} IN ALL FIELDS
RETURNING Contact(Id, FirstName, LastName)];

* allows matching text containing “Musa” anywhere in the field.

4. Fuzzy Matching for Similar Words

It seems that salesforce doesnt support fuzzy Match out the box. Drop a dm if you would like for me to create a apex class that would handle that kind of search. The benefits would be:

~ finds words like “Musa,” “Mossa,” or “Musaiah” — useful for typos.

5. Searching Custom Objects

Calling in query editor

FIND {Road} IN ALL FIELDS
RETURNING Fleet__c(Id, Name)

Calling in apex

List<List<sObject>> searchList = [FIND 'Road' IN ALL FIELDS
RETURNING Fleet__c(Id, Name)];

Works if Fleet__c is marked searchable and fields are indexed.

6. Handling Lack of WHERE or LIKE — Post-filter in Apex

SOSL does not support WHERE or LIKE clauses. Instead:

List<List<SObject>> results = [FIND 'Musa' IN ALL FIELDS RETURNING Contact(Id, FirstName, LastName)];

List<Contact> filteredContacts = new List<Contact>();
for (SObject s : results[0]) {
    Contact c = (Contact)s;
    if (c.LastName == 'Ndlala') {
        filteredContacts.add(c);
    }
}

Manually filter results after the SOSL query.

⚠️ Gotchas & Limits

  • No WHERE or LIKE in SOSL queries.
  • Only text-based fields are searchable (Name, Email, Phone, Text).
  • Objects must be marked searchable in Salesforce Setup.
  • SOSL automatically indexes fields; no manual index management.

💭 Final Thought

SOSL is your go-to tool when you want to search fast and broad across your org’s data. It’s simple once you grasp its limitations and strengths:

SOSL = fast multi-object text search without fine-grained filters.

Master this now, and you’re set for the PD1 exam and ready to level up for PD2. 👊 The SalesforceKlever way. 🚀


메타데이터
post_id
4ef38728ca62
slug
mastering-sosl-google-but-salesforce-style-basics-for-pd1-4ef38728ca62
url
https://medium.com/@kmniroi/mastering-sosl-google-but-salesforce-style-basics-for-pd1-4ef38728ca62
canonical_url
https://medium.com/@kmniroi/mastering-sosl-google-but-salesforce-style-basics-for-pd1-4ef38728ca62
author_url
https://medium.com/@kmniroi
status
ok
fetched_at
2026-06-16 19:09:56