function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Singer-ClarkSinger-Clark 

How can you get attached files of EmailMessages?

The documentation at https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_emailmessage.htm says there is a ContentDocumentIds field on the EmailMessage which could be used to go through a ContentDocumentLink object, then (using the ContentDocumentId field) through a ContentDocument object, and finally (using the
LatestPublishedVersionId field) to a ContentVersion object which holds the attached file's data.

The problem is that when I make a describe call to EmailMessage, "ContentDocumentIds" is not one of the fields listed.

Additionally, when I use SOQL to grab EmailMessages that have HasAttachment = True, and I SELECT the ContentDocumentIds field, while it doesn't error (surprising, since it's not listed as a field in the describe call), the value is None every time. So there is a few pieces of evidence that my approach is wrong.

Is there a way to get attachment data associated with an EmailMessage?