SOQL (Salesforce Object Query Language) is Salesforce's query language for retrieving records. Inspired by SQL but with key differences:
- No `SELECT *` — you must list every field. Fields not selected return null on the resulting sObject.
- Single-object queries with relationship traversal —
SELECT Id, Account.Name FROM Contacttraverses the lookup, but classic SQL JOIN syntax doesn't exist. You use dot notation for parent and subqueries for children:SELECT Id, (SELECT Id FROM Contacts) FROM Account. - Limited operators — no
UNION, noHAVING(useGROUP BY HAVINGonly), no full-text viaLIKE(use SOSL for that). - Governor-limit aware — every query counts against the per-transaction SOQL limit (100 sync, 200 async).
- Index-driven — for large tables, queries must hit indexed fields to be selective.
- Polymorphic queries — query on Lookup-to-Polymorphic relationships (
SELECT Id, What.Type FROM Task).
Use SOSL instead of SOQL for full-text search across multiple objects.
