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
Michael O'MalleyMichael O'Malley 

What connects an EmailMessage to a FeedItem?

Is there any way to tell to which FeedItem an EmailMessage belongs? The ParentId field on EmailMessage shows to which Case an EmailMessage belongs, but I can't find any way to figure out the parent FeedItem of the email message via Apex code or SOQL.

The linkage must exist somewhere because the Case feed knows where to display a given email message. Maybe the connection is hidden in an object that isn't exposed to Apex developers?

A similar question was asked here and never answered - https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=9062I000000QvsdQAC
ShirishaShirisha (Salesforce Developers) 
Hi Michael,

Greetings!

I don't think there is any direct relationship between the FeedItem and EmailMessage.Also,I have checked all the documentations related to these SObjects but couldn't find anything.

However,it might be possible that these are connected with the ParentId of both Objects.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Bob HatcherBob Hatcher
@Michael, did you ever find an answer to this? Thank you!
Tim Hunter 12Tim Hunter 12
Only reliable link I've been able to find is through the Connect in Apex (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectAPI_overview.htm) tools which make use of the ConnectAPI tools and API callouts to get the data related to each other. I've posted details about this over on StackExchange (https://salesforce.stackexchange.com/a/380454/85370) if you want to see an example. Basics overview is that you use the ConnectApi.ChatterFeeds (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_ConnectAPI_ChatterFeeds_static_methods.htm) methods to get the FeedElement/FeedItem you want then dig down in the related data to the ConnectApi.EmailMessageCapability (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_connectapi_output_email_message_capability.htm#apex_connectapi_output_email_message_capability) (if there's one associated to the FeedElement/FeedItem).