Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

In the realm of Salesforce, understanding the intricacies of its data model is crucial for effective customization and utilization of the platform’s functionalities. Among the nuances lies the concept of polymorphic fields, particularly evident in the Event and Task objects through the whoid and whatid fields. These fields play a pivotal role in associating records with various objects, enabling flexibility and efficiency in managing sales and customer interactions. In this blog post, I will delve into the disparities between whoid and whatid, shed light on their polymorphic nature, and provide examples of SOQL queries to leverage their capabilities.

Understanding WhoId And WhatId

Both whoid and whatid are standard fields in Salesforce’s Event and Task objects, serving distinct purposes:


  • Represents the “Who” in the interaction, typically referring to a contact, lead, or person account.
  • Allows the association of the event or task with a specific individual or entity.
  • Can point to records of various objects, such as Contact, Lead, or Person Account.


  • Denotes the “What” of the interaction, signifying the related record or object being acted upon.
  • Can refer to opportunities, accounts, campaigns, cases, or custom objects, depending on the context.
  • Enables tracking of activities related to specific opportunities, accounts, or other relevant entities.

Polymorphic Nature

The term “polymorphic” refers to the ability of a field to reference multiple object types. In the case of whoid and whatid, their polymorphic nature allows for flexibility in associating events and tasks with diverse records across Salesforce objects. This flexibility streamlines data management and enhances user experience by accommodating various business scenarios without necessitating extensive customization.

Example SOQL Queries

Utilizing SOQL queries, Salesforce developers and administrators can extract valuable insights and perform operations based on whoid and whatid fields. Here are some example queries showcasing their usage:

Retrieve all tasks associated with a specific contact:

SELECT Id, Subject, ActivityDate FROM Task WHERE WhoId = :contactId

Get the count of events related to opportunities:


Find tasks associated with accounts created after a certain date:

SELECT Id, Subject, ActivityDate FROM Task WHERE WhatId IN (SELECT Id FROM Account WHERE CreatedDate > :dateValue)

List events related to a particular campaign:

SELECT Id, Subject, ActivityDate FROM Event WHERE WhatId IN (SELECT Id FROM Campaign WHERE Name = 'Campaign Name')


In conclusion, understanding the nuances between whoid and whatid in Salesforce’s Event and Task objects is crucial for leveraging the platform’s capabilities effectively. These polymorphic fields offer flexibility in associating activities with diverse records across Salesforce objects, thereby enhancing data management and operational efficiency. By mastering the usage of SOQL queries with whoid and whatid, Salesforce users can unlock valuable insights and streamline their sales and customer interaction processes.


This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.


Submit a Comment

Your email address will not be published. Required fields are marked *