SendEmail
SendEmail copied to clipboard
EmailMessage does not contain RelatedTo-Id
Hey, I was wondering about the technical way the send email message (Object EmailMessage) is related to the Contact / Lead. I see the Message through the contacts activities, but on database-level when querying the EmailMessage I do not see a value in the field RelatedToId.
As far as I understand this would be needed to use Bounce Management and find bounced Emails in a report on Contact (e.g. isbounced, bouncereason).
Am I anything missing ? How is the connection to the contact done so the email is seen in the activity timeline ? I am not checking "Setting - save as activity".
Hey @Kerstin-Eigenherd,
RelatedToId does not link to an individual contact, lead, or user. According to Salesforce, it represents "nonhuman objects such as accounts, opportunities, campaigns, cases, or custom objects." It is a polymorphic relationship field, and is typically the Related Entity Type from the email template that was used for the send.
For tracking sender or recipient(s), whether as From, To, CC, or BCC, there is a separate object called EmailMessageRelation. Here the RelationId field is either a Contact, Lead, User, or null. The IsBounced flag remains on EmailMessage, however.
For the email message to appear on the activity timeline, Setting - Save as Activity must be checked.
Dear @jp-ed,
thanks for your feedback - I was not aware of the detailed explanation on how to use the RelatedToId on EmailMessages and I was definitely not aware of another object called EmailMessageRelation. Thanks for your insights!
I was looking into my specific issue again and I even think that me asking was due to the Email-Field already updated on the contact once and therefore the field IsEmailBounced already false again on contact but the EmailMessage still said IsBounced true.
Thank you for your quick and specific response, with those information and some more digging into the topic I resolved our issue.
Kind regards!