Skip to main content
VTFriday

Salesforce Activities: Tasks, Events, WhoId and WhatId

Updated

Source: https://www.vtfriday.com/2026/11/salesforce-activities-explained-tasks.html

💬 In plain words: Tasks are action items with due dates and statuses. Events are scheduled calendar meetings with start and end times. Both link to people through WhoId and to business records through WhatId, rolling into the Activity Timeline on every related record. Because activities follow special polymorphic relationship, sharing, archiving, and storage rules, keep automation on them light and plan for data growth early.
📌 Example: A discovery call with a Chief Financial Officer is logged as a completed Task. Next week's product demonstration is scheduled as an Event. Both appear chronologically on the Opportunity's Activity Timeline, acting as the deal's running diary. If you run an exception report showing Accounts with no completed activities in the last 60 days, you have built a neglect radar for at-risk relationships.

🔑 Key Points

  • Two core objects: In Salesforce, "Activities" is an umbrella term covering two standard objects: Task (to-dos and logged calls) and Event (calendar appointments).
  • Dual polymorphic lookups: Activities connect to people (Contact or Lead) using the WhoId field and to business context (Account, Opportunity, Case, or custom objects with activities enabled) using the WhatId field.
  • Automatic roll-up behavior: An activity linked to a Contact or Opportunity also rolls up to the parent Account's Activity Timeline automatically, giving teams a unified interaction view without extra custom automation.
  • Built-in archiving: Salesforce automatically archives completed Tasks and past Events that are more than 365 days old, removing them from standard reports and unarchived SOQL queries unless you explicitly query all rows.
  • Email storage divergence: Standard manual email logging creates EmailMessage and Task records inside Salesforce, whereas Einstein Activity Capture (EAC) stores captured emails and events outside the standard Salesforce object database, which directly alters how you build reports.

💡 Concept: How Salesforce Models Interactions

In almost every CRM implementation, teams need to answer two foundational questions about any customer or deal: What happened in the past? and What is scheduled to happen next? Salesforce answers both questions through the Activity data model rather than forcing you to build custom interaction tables for every object.

Instead of using a single generic table, Salesforce splits activities into two specialized standard objects that share common fields and user interface components:

  • Tasks (Task): Represent discrete actions, follow-up reminders, or completed interactions such as logged phone calls. A Task tracks a Status (for example, Not Started, In Progress, or Completed), a Priority, and a single due date (ActivityDate).
  • Events (Event): Represent blocked time on a calendar. Unlike a Task, an Event does not have a completion status; it is governed by a StartDateTime and an EndDateTime (or an all-day flag). Once the end time passes, the Event naturally shifts from the "Upcoming & Overdue" section of the Activity Timeline into the historical log.

Polymorphic Relationships: WhoId and WhatId

In a standard lookup relationship, a field points to only one target object—for example, an Opportunity's AccountId field can only point to an Account. If activities used standard lookups, the Task object would need dozens of separate lookup columns for every standard and custom object in your org.

To prevent that schema bloat, Salesforce uses polymorphic lookup fields—single lookup fields that can point to one of several possible object types:

  • WhoId (Labeled "Name" in the UI): Points to a human being—specifically a Contact or a Lead. Notice the critical validation constraint: if WhoId points to a Lead, you cannot populate WhatId on the same activity because an unconverted Lead does not belong to an Account or Opportunity yet.
  • WhatId (Labeled "Related To" in the UI): Points to a non-person business record such as an Account, Opportunity, Case, Campaign, or any custom object where you have checked the Allow Activities setting in Object Manager.

Additionally, Salesforce automatically maintains a read-only AccountId field on every activity. Even if a user only links a Task to an Opportunity (WhatId) or a Contact (WhoId), Salesforce resolves the parent Account behind the scenes and populates AccountId so the interaction surfaces on the Account's timeline as well.

🛠️ Worked Example: Linking a Task to Multiple Contacts and an Opportunity in Apex

Suppose your org has Shared Activities enabled (found under Setup → Activity Settings → Allow Users to Relate Multiple Contacts to Tasks and Events). A sales engineer completes a technical call with two Contacts regarding an active Opportunity, and you need to log this interaction programmatically.

Prerequisites & Execution Context: This illustrative code snippet runs in an Apex service class or Anonymous Apex window. The running user must have "Edit Tasks" permissions and at least Read access to the target Contacts and Opportunity.

public class ActivityLoggerExample {
    public static Id logMultiContactCall(Id opportunityId, Id primaryContactId, Id secondaryContactId) {
        if (opportunityId == null || primaryContactId == null) {
            throw new IllegalArgumentException('Opportunity ID and Primary Contact ID are required.');
        }

        // 1. Insert the Task with the primary Contact (WhoId) and Opportunity (WhatId)
        Task callLog = new Task(
            Subject = 'Technical Architecture Review Call',
            Status = 'Completed',
            Priority = 'Normal',
            TaskSubtype = 'Call',
            ActivityDate = Date.today(),
            WhatId = opportunityId,
            WhoId = primaryContactId,
            Description = 'Reviewed integration limits and API authentication flow.'
        );
        insert as user callLog;

        // 2. If Shared Activities is enabled and a second Contact attended, create TaskRelation
        if (secondaryContactId != null && secondaryContactId != primaryContactId) {
            TaskRelation secondaryAttendee = new TaskRelation(
                TaskId = callLog.Id,
                RelationId = secondaryContactId,
                IsWhat = false // False indicates a Contact/Who relation rather than WhatId
            );
            insert as user secondaryAttendee;
        }

        return callLog.Id;
    }
}

How to validate the expected result: After running the method with valid record IDs in a sandbox, open the Opportunity record page and both Contact record pages in Lightning Experience. You should see "Technical Architecture Review Call" under the Past Activities section of the Activity Timeline on all three records, as well as on the parent Account.

⚠️ Common Traps to Avoid
  • Confusing Einstein Activity Capture (EAC) with database records: When you enable Einstein Activity Capture to sync Microsoft Outlook or Google Workspace emails and calendars, Salesforce stores those captured emails in external infrastructure rather than creating standard Task or EmailMessage rows in your core database. As a result, standard Salesforce "Tasks and Events" reports will not show EAC-captured emails, and Apex triggers on Task will not fire for them.
  • Writing heavy triggers or Flows on Task and Event: Because automated email integrations, dialers (CTI), and marketing tools insert Tasks in large batches, putting complex record-triggered Flows or synchronous SOQL-heavy Apex triggers on Task is one of the fastest ways to cause UNABLE_TO_LOCK_ROW errors on parent Accounts and Contacts.
  • Forgetting the 365-day automatic archive filter: By default, Salesforce marks completed Tasks and ended Events older than 365 days with IsArchived = true. A standard SOQL query (SELECT Id FROM Task WHERE WhatId = :accId) silently omits archived records. To include archived activities in Apex, you must use ALL ROWS in SOQL (which also returns deleted records in the Recycle Bin, so filter with WHERE IsDeleted = false).
🧠 Core Rule: Task = to-do (due date). Event = calendar block. WhatId = related business record, WhoId = person. Activity Timeline = interaction history. High volume = performance watch.
🧭 360 Card — Activities: Tasks & Events

Rule: A Task is an action item or logged interaction; an Event is a scheduled time block. WhoId links to the person (Contact or Lead), and WhatId links to the business object.
Gain: A unified timeline on every record that tells the chronological story of the customer relationship without custom UI development.
Price: Activities quickly become the highest-volume tables in most orgs, yet teams rarely design archiving or indexing strategies for them upfront.
Limits: WhoId only accepts Leads or Contacts (up to 50 Contacts when Shared Activities is enabled). WhatId accepts a single non-person record. Activity visibility typically inherits from the parent record unless controlled separately.
Mirror — logging interactions in a custom object: Building a custom Interaction__c object gives you standard lookup fields and full sharing control, but you lose the Lightning Activity Timeline, native calendar sync, CTI dialer compatibility, and standard activity reporting.
Later: Activities are a Large Data Volume (LDV) challenge in disguise. Millions of unindexed tasks degrade related lists, parent record locks, and activity reports.
At volume: Plan archiving, selective indexing, and retention rules for activities using the same rigor you apply to any other multi-million-row object.

💬 Core Q&A

Q: How do Tasks and Events relate to other records, and what's the WhoId/WhatId distinction?
🎯 Say this first: WhoId = the person (Lead or Contact); WhatId = the business record (Account, Opportunity, or custom object); both roll into the related record's Activity Timeline.

A: An activity links to a business record through WhatId—the non-person record, such as an Account, an Opportunity, a Case, or an activity-enabled custom object. Simultaneously, it links to a person through WhoId, which must be a Contact or a Lead.

  • Because both fields exist on the same record, a phone call logged as a Task can be "about" an Opportunity (via WhatId) and "with" a Contact (via WhoId). Salesforce then surfaces that single Task on both records' Activity Timelines, plus the parent Account's timeline.
  • Enabling Shared Activities lets users relate up to 50 Contacts (one primary WhoId plus up to 49 additional Contacts stored in TaskRelation or EventRelation) to a single activity, along with one WhatId.
  • In Apex, you assign WhatId and WhoId directly on the Task or Event instance before insertion, and standard activity report types use those exact polymorphic relationships to join interaction metrics back to pipeline records.

🔍 Follow-ups (Scenario-Based)

Q1: Activity volume is huge and reports/timelines are slow. Considerations?

A1: Activities almost always turn into a Large Data Volume (LDV) bottleneck as an org matures:

  • When Task and Event tables grow into the tens of millions of rows, unselective reports time out, record page timelines lag, and bulk integrations encounter parent record lock contention (UNABLE_TO_LOCK_ROW).
  • Establish an archiving tier: While Salesforce's built-in archiving hides activities older than 365 days from standard reports, those rows still count against your data storage and remain in the underlying database table. For true scale, extract cold historical activities (for example, older than 2 or 3 years) into a custom Big Object or an external data lake, and delete them from the operational Task and Event tables.
  • Enforce selective report filters: Train report builders to always filter activity reports on indexed fields (CreatedDate, ActivityDate, OwnerId, WhoId, WhatId) and narrow date ranges rather than running unbounded "All Time" queries.
  • Curb noisy auto-logging: Audit marketing automation connectors and CTI integrations so they do not create a Task for every minor promotional email open or automated system notification.
  • Understand your email architecture: Remember that Einstein Activity Capture keeps email and calendar data off the core Task object, which saves Salesforce data storage but shifts reporting to Activity Metrics and EAC dashboards rather than standard SOQL reports.
  • Design principle: Balance the business desire for complete historical visibility against daily operational speed—keep hot activities queryable on the timeline, and move the cold tail to archive storage.
Q2: You need to restrict which users can see certain activities (private meeting notes). How does activity sharing work?

A2: Activities use a specialized visibility model that differs from standard object Organization-Wide Defaults (OWDs):

  • Controlled by Parent vs. Private: In Sharing Settings, the Organization-Wide Default for Activity can be set to either Controlled by Parent or Private. When set to Controlled by Parent, a user can view an activity if they can view either the WhoId record or the WhatId record (and edit/delete depends on role hierarchy, ownership, and profile permissions).
  • The Private OWD option: When the Activity OWD is set to Private, only the activity owner and users above the owner in the Role Hierarchy (plus administrators with View All Data) can see the activity, even if other users have read access to the parent Account or Opportunity.
  • Segmented visibility with Restriction Rules: What if two divisions share the same Account and use Controlled by Parent, but executive M&A notes or HR-sensitive tasks must be hidden from general sales reps? Salesforce supports Restriction Rules on both Task and Event (available in Enterprise, Performance, Unlimited, and Developer Editions). A Restriction Rule applies a filter on top of existing sharing so that matching users only see activities that meet your criteria (for example, Is_Confidential__c = false).
Q3 (Next Concept Connection): If you move cold activities older than two years out of the Task table into a custom Big Object, how do users still view that history on the Account page?

A3: Once you delete old Task records and write them into a custom Big Object (for example, Archived_Activity__b), they no longer appear in the standard Lightning Activity Timeline component. To keep them accessible to end users without hurting database performance, define the Big Object's composite index starting with the parent record ID (Account_Id__c or What_Id__c) followed by the activity date. Then, place a lightweight Lightning Web Component (LWC) in a separate "Archived History" tab on the Account Lightning Record Page that runs an indexed SOQL query against Archived_Activity__b only when a user clicks that tab.

📝 2-Minute Self-Check

Q1. A sales rep tries to save a Task where WhoId points to an unconverted Lead and WhatId points to an Account, and the save fails. Why?
A1. Salesforce enforces a platform validation rule preventing WhatId from being populated whenever WhoId references a Lead. Because a Lead has not yet been converted into a Contact, Account, and Opportunity, an activity linked to a Lead cannot simultaneously link to a WhatId business record.

Q2. An admin builds a custom report on Tasks to audit customer calls from 18 months ago, but known completed calls are missing from the results. What happened?
A2. Salesforce automatically archives completed Tasks and past Events whose due date or end date is more than 365 days ago (IsArchived = true). Archived activities are excluded from standard Salesforce reports and regular SOQL queries; to query them via the API or Apex, you must use ALL ROWS (or queryAll()) and filter out deleted records (IsDeleted = false), or request an archive threshold extension from Salesforce Support.

Q3. Two divisions share Read/Write access to the same Account under "Controlled by Parent" activity sharing, but one division's legal tasks on that Account must be hidden from the other division. What declarative feature solves this?
A3. An active Restriction Rule on the Task object. Because Organization-Wide Defaults and Sharing Rules only open up access, a Restriction Rule is required to filter out specific Task or Event records that a user would otherwise inherit visibility to through the parent Account.

Was this article helpful?

Have a question or spotted a mistake? Ask here about this article

Found this guide useful? Buy me a coffee (opens in a new tab)

Comments

Questions, corrections and your own experience are all welcome.