Development questions
Write a SOQL query to fetch Tasks where the WhoId (Polymorphic lookup) points only to a Lead and not a Contact (WHERE Who.Type = 'Lead').
WhoId is polymorphic (Lead or Contact). Filter on the related type with Who.Type.
soql
SELECT Id, Subject, WhoId, Who.Name FROM Task WHERE Who.Type = 'Lead'
This returns only Tasks whose Who is a Lead and excludes those pointing to Contacts.
soqlscenariopolymorphic
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?