As I attempt data migration from one Salesforce org to another, I am finding EmailMessage to be a very unnecessarily complicated object to understand. At one point I thought I understood that recent updates around "Enhanced Emails" made the EmailMessage
object similar to an Activity
which is why it appeared in the Activity Timeline.
After further review of the documentation (Exhibit A & Exhibit B), it appears that Salesforce creates a Task Activity (prefix 00T
) for each Email generated through the interface. Unexpected, but makes sense, but the problem is this "Task" doesn't exist anywhere that I can verify. I can search it through the interface and it doesn't return through a SOQL query of the ID.
How am I to migrate these message? I have 34k that have a RelatedToId
for an Account, Opportunity, or Quote, but then I have 28k that have no RelatedToId
. Of those 28k null values, some of them have an ActivityId
and some do not (the ones that do not appear to be internal System Account emails which I am less concerned with).
Can someone provide some detail around EmailMessage and the requirements around migrating records for this object?
Update
Some more details I have uncovered. I had an Account with 2 EmailMessages in the Activity Timeline. I deleted one using the Dev Console, hoping that by only removing the EmailMessage
the Task would remain and it would just link there. Unfortunately, it removed it all together... not that bad considering the Task and EmailMessage should be linked that probably makes the most sense.
That said, what I don't understand is why the second EmailMessage when queried, the ActivityId can not be seen, if I go to the 00T Id I get the following message
But after reinserting the EmailMessage
I removed I can access it's 00T ActivityId without an issue. It's worth noting that there are lots of instances where these so-called related Tasks appear to not exist, they can't even be queried directly. I see no pattern to these "black-boxed" Tasks.