1

Using the REST API I'm trying to pull, for a certain contact, when was the last date of email communication with them - last email sent to them.

My logic was to query a contact's activity history, filtering for AcitivitySubtype = 'Email' make sure the list is sorted properly (DESC) and then fetch the first entry.

This approach works but for some reason some emails do not appear in the activity history query although are clearly presented in the SF Lightning UI when I view the same contact.

For example, when viewing UI (under Past Activities):

  • Contact has email sent to them on Feb 13th
  • and also email sent to them on Jan 10th

Using this SOQL query:

SELECT Id, FirstName, LastName, ..., 
     (SELECT Subject, ActivityDate, ActivitySubtype FROM ActivityHistories
      ORDER BY ActivityDate DESC, LastModifiedDate DESC
      LIMIT 100)
FROM Contact
WHERE Id = SOME_ID

I only receive results that contain the earlier email from Jan 10th. What's interesting is that the Feb 13th email is marked in UI as 'not tracked' while Jan 10th email is not.

If I query Task objects instead of Contact's Activity History I still do not get that last email over the API.

Is it the case that untracked emails reside under a different Object? How is the UI showing them but I cannot retrieve them from API.

PS: same user is logged in when using API and using Lightning UI so not a permissions issue related to the user.

Your Answer

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

Browse other questions tagged or ask your own question.