Development questions
Write a SOSL query to search for the string 'Universal' across Account, Contact, and Lead returning specific fields from each object (FIND 'Universal*' IN ALL FIELDS RETURNING Account(Id, Name), Contact(Id, LastName, Email), Lead(Id, Company)).
SOSL searches text across multiple objects and returns a list of lists, one per object in the RETURNING clause.
apex
List<List<SObject>> results = [FIND 'Universal*' IN ALL FIELDS
RETURNING Account(Id, Name), Contact(Id, LastName, Email), Lead(Id, Company)];
List<Account> accs = (List<Account>) results[0];
List<Contact> cons = (List<Contact>) results[1];
List<Lead> leads = (List<Lead>) results[2];
The * is a wildcard; use IN NAME FIELDS to limit the search scope.
soslscenariosearch
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?