Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce Developer
easy

What is the difference between SOQL and SOSL?

Both query Salesforce data, but they answer different questions.

SOQL queries a single object (with related-record traversal) and returns specific records matching WHERE filters. Use when you know the object and can express criteria as field comparisons.

apex List<Account> accs = [SELECT Id, Name FROM Account WHERE Industry = 'Tech'];

SOSL searches text across multiple objects at once using a search-engine index. Returns a list of lists — one per object searched. Use for full-text "find all records mentioning 'acme'".

apex List<List<SObject>> results = [FIND 'acme' IN ALL FIELDS RETURNING Account, Contact, Lead];

Differences:

  • Object scope: SOQL is single-object; SOSL is multi-object.
  • Match type: SOQL is exact field comparisons; SOSL is text search with stemming.
  • Performance: SOSL is fast for ambiguous searches across many objects; SOQL is fast when you know what you're looking for.
  • Result shape: SOQL returns one list of sObjects; SOSL returns nested lists per object.

Default to SOQL. Reach for SOSL when the user's input is search-style ("find anything with this name").

Why this answer works

Foundational. The "multi-object search vs single-object query" framing is the cleanest distinction. Showing the syntax examples is a strong signal.

Follow-ups to expect

Related dictionary terms