WhoId and WhatId in Salesforce: Clear Definitions, Examples and SOQL Usage

If you have ever wondered why a Task you created does not appear where you expected it in Salesforce, the answer often comes down to two small fields: WhoId and WhatId. These fields play a crucial role in linking activities to the correct records, yet they frequently cause confusion among admins, developers and consultants alike.

The confusion typically stems from three sources. First, both fields appear together on every Task and Event, making it unclear which one to prioritise. Second, their user interface labels (“Name” and “Related To”) do not match their API names (WhoId and WhatId), which trips up anyone switching between clicks and code. Third, both are polymorphic fields, meaning they can point to different object types depending on the record ID you supply.

This blog post will answer the essential questions: what is WhoId, what is WhatId, how do they differ, and how do they impact reporting, automation and SOQL queries? We will use practical examples throughout, such as a Task linked to a Contact and an Opportunity (for instance, “Call John Smith about Opportunity Q1 Renewal”). Whether you are an admin configuring page layouts, a consultant auditing data quality, or a developer writing Apex triggers, this guide will give you the clarity you need.

Quick Answer: WhoId vs WhatId in Salesforce

Here is the short version before we go deeper.

Understanding WhoID

WhoId represents an API field on task and event objects. In the user interface, it appears as the “Name” field. It always points to a person record, specifically a Lead or Contact.

Understanding WhatId

WhatId is also an API field on task and event objects. In the user interface, it appears as the “Related To” field. It points to non-person records such as Account, Opportunity, Case, Campaign, Contract and custom objects.

The core difference in one sentence: WhoId = who you are interacting with; WhatId represents what that interaction is about.

Both fields are polymorphic lookup fields that store an 18-character Salesforce record ID. Later sections will explain Activities, SOQL queries, reporting implications and automation considerations in detail.

Salesforce Activities and Polymorphic Relationship Fields

Activities is the umbrella term Salesforce uses for Tasks and Events. Think of a phone call you need to make (a Task) or a meeting you have scheduled (an Event). Both relate to customer interactions and both share the same core fields, including WhoId and WhatId .

The Activity concept is abstract. In practice, you work with two separate standard objects:

  • Task – actionable items like calls, emails or follow-ups

  • Event – scheduled occurrences like meetings, demos or workshops

A real-world example: you might have a phone call (Task) and a subsequent meeting (Event) for the same Opportunity. Both records can share the same WhoId (the Contact you spoke with) and WhatId (the Opportunity you discussed).

What Are Polymorphic Relationship Fields?

A polymorphic field can point to more than one object type. Compare this to a standard lookup field, like AccountId on Contact, which references only the Account object. The WhoId field, by contrast, can reference either a Contact or a Lead depending on the ID you provide.

The WhatId field supports multiple other objects, including:

  • Account

  • Opportunity

  • Case

  • Campaign

  • Contract

  • Asset

  • Custom objects like Projectc, Subscriptionc or Retainer__c

Understanding this polymorphic structure is essential for building correct reports, automations and SOQL queries. Without it, you risk Activities appearing in unexpected places or not appearing at all.

A professional is seated at a modern office desk, intently reviewing data displayed on a laptop screen, which likely includes insights related to customer interactions and various Salesforce records. The environment suggests a focus on tracking and managing new tasks, opportunities, and relationships within a dynamic sales cloud setting.

What Is WhoId in Salesforce?

WhoId is the “person” link on Tasks and Events. It connects an Activity to a Contact or Lead, whichever individual you interacted with.

UI Mapping

In the Salesforce user interface, WhoId appears as the Name field on Task and Event page layouts. When a user clicks that field, they search for and select a Contact or Lead’s ID.

Supported Objects

WhoId only supports two objects:

  • Contact – a person associated with an Account (e.g. John Smith at Acme Ltd)

  • Lead – a prospect not yet converted (e.g. Jane Doe – New Business – London)

Concrete Examples

ActivityWhoId ValueDescription
Task: “Call John Smith to confirm contract renewal”Contact: John SmithSales rep logging a follow-up call
Event: “Discovery call with Jane Doe”Lead: Jane DoeInitial meeting with an unconverted prospect

Shared Activities

When Shared Activities is enabled in your Salesforce environment, a single Task or Event can link to up to 50 Contacts via WhoId. This is useful for logging a meeting attended by multiple people. Note that Leads cannot be part of Shared Activities; Contacts only.

Important Rule for Leads

If WhoId points to a Lead, Salesforce cannot automatically associate an Account. Leads are not yet tied to the Account object. Once you convert a Lead to a Contact, the relationship with an Account is established, and the account id can be derived from the Contact.

If you use a Contact in WhoId, Salesforce can infer the related Account and auto-populate the Account field on the Task or Event.

What Is WhatId in Salesforce?

WhatId connects a Task or Event to a “thing” or business record, anything that is not a person. Understanding WhatId is key to accurate reporting across deals, cases and campaigns.

UI Mapping

In the user interface, WhatId appears as the Related To field. Users search for other records, such as Opportunities, Accounts, Cases, and custom objects.

Common Standard Objects

Object Example Record
Account Acme Ltd – UK
Opportunity Q2 – Website Redesign – £65,000
Case URGENT – Checkout not working – 00013579
Campaign 2025 Spring Email Nurture – Segment A

Concrete Use Case

Task: “Send proposal” related to Opportunity “Q1 Renewal – AWS Hosting”

Here, WhatId stores the opportunity id. This means the opportunity record’s activity timeline will display that Task, giving sales reps full visibility of deal-related interactions.

Behaviour with Leads

If WhoId points to a Lead, WhatId cannot reference an Account directly from that Lead because no Account relationship exists yet. For full context, consider using Lead conversion to establish the Contact-to-Account relationship first.

Custom Objects Support

WhatId also supports custom objects. For example:

  • Project__c: “New Product Launch – Q3 Marketing Campaign”

  • Implementation__c: “Salesforce Integration – Phase 1”

  • Retainer__c: “Ongoing Support – Enterprise Client”

This flexibility lets service businesses track Activities against bespoke records that reflect their operations.

Side-by-Side Comparison: WhoId vs WhatId

The table below summarises the key differences between these two fields.

AspectWhoIdWhatId
UI LabelNameRelated To
Object TypesLead, ContactAccount, Opportunity, Case, Campaign, Contract, Asset, custom objects
Data TypePolymorphic lookupPolymorphic lookup
Example RecordJohn Smith (Contact)Q2 Website Redesign (Opportunity)
Typical UsageWho you spoke toWhat the conversation was about
Account Auto-PopulationYes, if Contact is used (derives from Contact’s Account)Indirectly, via the related object’s Account

Memory aid: Who = person, What = business record.

The similarities end at both being polymorphic lookups on the same objects. Their purposes and the records they reference are entirely distinct.

Real-World Use Cases: Tasks and Events with WhoId and WhatId

Concrete scenarios help cement the difference between these fields. Here are four examples you might encounter in a typical B2B organisation.

Example 1: Sales Follow-Up Task

A sales rep at a digital agency calls a prospect about a new website project.

  • WhoId: Contact = Sarah Green – Marketing Director – New York Legal Group

  • WhatId: Opportunity = Q2 Marketing Campaign – New York Legal Group

This Task appears on both the contact record and the opportunity record timelines, providing full visibility to anyone reviewing either record.

Example 2: Pre-Sale Discovery Event

A scoping workshop is booked with a client.

  • WhoId: Contact = James Brown – CEO – London Fintech Ltd

  • WhatId: Opportunity = Bespoke Client Portal Build – 2025

The Event shows under both relationships, making it easy for account managers and sales reps to track engagement.

Example 3: Lead Nurturing

A marketing coordinator reviews demo feedback.

  • WhoId: Lead = Emma Wilson – SaaS Start-up – Bristol

  • WhatId: Campaign = 2024 Q4 Product Demo Series

This helps marketing analyse follow-up activity per Campaign and associate activities with specific lead records before conversion.

The image depicts a business professional seated at a desk, engaged in a phone call, illustrating a moment of customer interaction. The setting reflects a sales environment, where the individual may be discussing opportunities or tasks related to various Salesforce records, such as contact and opportunity IDs.

Example 4: Support Case

A support agent re-tests a bug after a fix.

  • WhoId: Contact = Tom Hughes – Marketing Director – Global Tech Solutions

  • WhatId: Case = High Priority – eCommerce checkout errors – 00024680

This is common when service and product teams collaborate on issues. The Task links to both the customer and the specific Case.

Accurate WhoId and WhatId usage keeps Activity history meaningful across Contacts, Accounts, Opportunities and Campaigns.

Reporting and Automation Implications

Choosing between WhoId and WhatId correctly affects dashboards, list views, and automation logic throughout your Salesforce org.

Reporting Considerations

Activity reports can be filtered by:

  • WhoId type: Activities with Contacts vs Activities with Leads

  • WhatId type: Activities related to Opportunities only, or Cases only

For example, a “Sales Activity by Opportunity Stage” report relies on WhatId being consistently set to Opportunities. If reps leave WhatId blank, those Activities will not appear in pipeline reports.

Lead vs Contact Reporting

Tasks where WhoId equals a Lead will not appear on Contact or Account reports until Lead conversion. If your business converts Leads regularly, plan for this transition in your reporting strategy.

Account-Level Rollups

Using a Contact in WhoId allows Salesforce to implicitly connect Activities to the related Account. If you only set WhatId to an Opportunity, the Activity still surfaces on the Account via the Opportunity relationship, but setting both fields gives you maximum flexibility.

Automation: Flows, Process Builder and Apex

Because WhoId and WhatId are polymorphic fields, automation must check the sObject type at runtime. In Record-Triggered Flows, decisions often branch on questions like:

  • Is WhoId a Contact or a Lead?

  • Is WhatId an Opportunity or a Case?

For example, you might send different email templates depending on whether a Task is for a Lead or Contact.

Concrete Flow Scenario

When a Task is completed and WhatId is an Opportunity in stage “Proposal/Price Quote”, a Flow could:

  1. Update the Opportunity’s “Last Activity Date”

  2. Increment an “Engagement Score” field

  3. Notify the Account Owner

Poor use or absence of WhoId and WhatId leads to incomplete reports and automations that fail silently.

SOQL Examples: Querying WhoId and WhatId

Developers and admins using Developer Console, Workbench or tools like VS Code frequently need to query Activities by WhoId and WhatId.

Basic Query: Tasks for a Specific Contact

SELECT Id, Subject, Status, WhoId, WhatId 
FROM Task 
WHERE WhoId = '003XXXXXXXXXXXXXXX'

Replace the ID with a real contact id from your org.

Tasks Related to an Opportunity

SELECT Id, Subject, Status, WhoId 
FROM Task 
WHERE WhatId = '006YYYYYYYYYYYYYYY'

Use case: listing all follow-up Tasks for Opportunity “2025 Website Redesign – Acme Ltd.”

Understanding Polymorphic Fields with TYPEOF

For API versions that support it, you can use TYPEOF to handle polymorphism:

SELECT Id, Subject,
  TYPEOF Who
    WHEN Contact THEN FirstName, LastName, Account.Name
    WHEN Lead THEN FirstName, LastName, Company
  END
FROM Task
WHERE WhoId != null

Filtering by ID Prefix

Salesforce IDs have predictable prefixes:

  • Contact: 003

  • Lead: 00Q

  • Opportunity: 006

  • Account: 001

You can filter accordingly, though use this approach with caution:

SELECT Id, Subject 
FROM Task 
WHERE WhoId LIKE '003%'

This returns Tasks where WhoId is a Contact, not a Lead.

Limitation

You cannot do a direct foreign-key-style relationship query like That.Name because of polymorphism. You typically resolve this via separate queries or TYPEOF for supported API versions.

Combined Filter Example

Query all open Tasks related to Opportunities where WhoId is a Contact:

SELECT Id, Subject, Status, WhoId, WhatId
FROM Task
WHERE Status != 'Completed'
AND WhatId LIKE '006%'
AND WhoId LIKE '003%'

This is useful for sales pipeline dashboards focusing on active deal-related activities with established Contacts.

Common Mistakes and Troubleshooting Tips

Many orgs misuse or ignore these other fields, leading to reporting gaps and automation failures.

Mistake 1: Only Using WhoId and Ignoring WhatId

Tasks end up visible on Contacts but not clearly tied to specific Opportunities or Cases. Always fill WhatId when the activity relates to a particular deal, project or issue.

Mistake 2: Using Leads When Contacts Would Be Better

Long-running B2B relationships should use Contacts and Accounts rather than leaving records as Leads indefinitely. Activities stuck on Leads can become invisible in account-level and pipeline reporting.

Mistake 3: Using Custom Fields Instead of Proper Relationships

Some orgs create text fields like “Opportunity Name” on Task instead of setting WhatId. This breaks rollups, prevents Activities from appearing on related lists, and requires manual maintenance.

Mistake 4: Automation Not Checking Record Type

Flows or Apex that assume WhoId is always a Contact will fail when it references a Lead. Always test the sObject type before accessing object-specific fields.

Troubleshooting Checklist

  • Verify page layouts include both Name (WhoId) and Related To (WhatId)

  • Confirm user permissions to view related objects (Account, Opportunity, etc.)

  • Check if Shared Activities is enabled when needing multiple Contacts on one Activity

  • Review recent automations that might be overwriting WhoId or WhatId unexpectedly

  • Run reports to identify Activities where WhoId or WhatId is blank

Periodically audit Activities with missing relationships and fix them with data cleanup jobs.

Summary: When to Use WhoId vs WhatId

WhoId is for the person you interacted with, Lead or Contact. WhatId is for the business record Account, Opportunity, Case, Campaign or custom objects that the interaction relates to. Both are polymorphic fields on Task and Event that power Salesforce’s Activity model.

The key rule: Always set both fields whenever possible. Who did you talk to? What was it about?

Getting this right impacts:

  • Reporting: Accurate activity histories on Contacts, Accounts and Opportunities

  • Automation: Flows and Apex that react to specific customer interactions

  • Data model clarity: Clean, reliable timelines for every customer and deal

Next Steps

  1. Audit a sample of recent Tasks and Events to see if WhoId and WhatId are being used correctly

  2. Review your page layouts to ensure both fields are visible and required where appropriate

  3. Align training and automation logic to enforce good Activity data hygiene

Teams relying heavily on Salesforce data, whether for analytics, web portals or customer dashboards, should keep their Activity relationships clean to ensure accurate downstream insights.

Reach the most targeted
audiences in half the time