Development questions
What are the key differences between SOQL and SOSL, and when do you choose one over the other?
| SOQL | SOSL | |
|---|---|---|
| Purpose | Query records of one object (plus related) | Text search across many objects and fields |
| Returns | List of sObjects | List of lists of sObjects |
| Search | Field-based WHERE filters | Full-text search index, word matching |
| Limits | 100 queries, 50,000 rows | 20 SOSL queries, 2,000 rows each |
| Use when | You know the object and need filtered/related data, aggregates | You don't know which object/field holds the text, or need fuzzy text search |
apex
List<List<SObject>> r = [FIND 'Acme*' IN ALL FIELDS RETURNING Account(Id, Name), Contact(Id, Name)];
soqlsoslfundamentals
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?