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
Caleb Kuester 27Caleb Kuester 27 

How Do You Get ContentDocumentIds From Trigger

Greetings!

I have an EmailMessage trigger where, given any insertion of an EmailMessage, I'm looking to get the ContentDocumentIds from each message (attachments), The problem is that the ContentDocumetnId fields are blank on EmailMessage trigger. Trigger.new has a list of EmailMessage records with blank ContentDocumentIds.

The twist is that, in the Execute Anonymous window, if I query for the EmailMessage objects and corresponding ContentDocumentIds by their Ids, they have ContentDocumentIds.

As my application is specifically relevant to the Case record (Case records created by Email-to-Case), I have also attempted to reach them after the Case records were created, given this should be way after the EmailMessage records are fully created, but this is a problem because, at this stage, EmailMessage records do not have their parentId fields populated with the case, even after insert.

I feel like I am missing something silly, but I can't figure out what that is. Google only has maybe two relevant results and they are different enough to not be useful.
AbhishekAbhishek (Salesforce Developers) 
Hi Caleb,

Can you try this as per this blog,

https://salesforce.stackexchange.com/questions/76121/retrieve-all-contentdocument-ids-whose-related-contentdocumentlink-record-is-upd

https://help.salesforce.com/articleView?id=000312746&type=1&language=en_US&mode=1

It might help you.

Thanks.