# 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').

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Salesforce, Deloitte, Slalom · **Tags:** soql, scenario, polymorphic

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-tasks-where-the-whoid-polymorphic-lookup-points-only-to-a-lead-and-not-a-contact

## Answer

`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.

---
Source: ForceChallenges · last updated 2026-10-19
