# How do you query Polymorphic lookup fields like What and Who on Task/Event or Owner using TYPEOF in SOQL?

**Topic:** Soql · **Difficulty:** Hard · **Asked at:** Salesforce, Deloitte, Slalom · **Tags:** soql, polymorphic, typeof

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-you-query-polymorphic-lookup-fields-like-what-and-who-on-task-event-or-owner-using-typeof-in-soql

## Answer

`TYPEOF` lets you select different fields depending on the actual object type of a polymorphic relationship (`What`, `Who` on Task/Event, `Owner`, etc.).

```soql
SELECT Id, Subject,
  TYPEOF Who
    WHEN Lead    THEN Company, Email
    WHEN Contact THEN Account.Name, Department
    ELSE Name
  END
FROM Task
```
You can also filter polymorphic fields with `Who.Type = 'Lead'`.

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