Specifically regarding Email objects in Salesforce's REST API, i get redundant AccountIds on fields- AccountId and WhatId. Seems like both of these are Accounts related to the Task.

My query to fetch emails is-

SELECT AccountId,CreatedById,Description,Id,Subject,SystemModstamp,WhatId,WhoId FROM Task WHERE Subject LIKE 'Email: %'


The AccountId is special part of the native display of "360 degree view" of the customer. This field can be used to query all tasks and events that tell a story around the Account. The value is populated automatically by all native objects that relate to Account directly or indirectly via WhoId or WhatId.

taskevent taskevent taskevent taskevent taskevent (tasks and events WhatId related to native objects)

||   ||   ||   ||  ||
vv   vv   vv   vv  vv

asset case contract opportunity order

  \   \   |   /   /
   v   v  v  v   v

Account Id account taskevent (account also has own tasks and events)

         ^ ^
        /   \

blank16 blank32contact lead

       ^^   ^^
       ||   ||

blank16blank32 taskevent taskevent (tasks and events WhoId related to native objects)


  • Account (the top of the graph from which all activities will be seen)
  • Asset
  • Case
  • Contract
  • Opportunity
  • Order


  • Contact (emails and calls to contacts will be seen on the Account)
  • Lead (when converted, all prospecting activities remain on the Contact)

Use the AccountId instead of the WhatId to get the full picture like this:

List<Task> emails = [
    SELECT Id, Subject, Description
    FROM Task
    WHERE AccountId = :accountId
    AND Subject LIKE 'Email:%'

It is also possible for Tasks and Events hanging off Custom Objects to appear on the Account, if that object is designed with a Master-Detail relationship to Account. This doesn't work when it is a Lookup relationship, or when the relationship connects to other native objects hanging off Account.


Task API object here

"This is the account of WhatId if it exists, otherwise it’s the account of WhoId if it exists, otherwise it’s set to null"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.