I am trying to figure out how to copy emails + attachments from one system to SF using a java application.
When creating an email from the Salesforce Lightning UI, an EmailMessage and a Task is created. This way it shows up in the Activity timeline of the contact and by clicking the link you get redirected to the email.
I managed to do the same, create an EmailMessage and a Task, but the task is not related to the mail message. When clicking the link in the activity, I go to the task object and not the MailMessage. It also doesn't display as nicely. It makes sence because I don't relate the task id to the mail message, because the EmailMessage.AcitivityId is not writable...
I set the following fields:
MailMessage: subject, textBody, toIds, ccIds, bccIds, toAddress, ccAddress, bccAddress, attachments Task: whoId, subject, messageDate, status(completed), priority(normal), isReminderSet(false), isRecurrence(false), taskSubtype(Email), description(plain text representation of mail)
*ps: Other topics refer to the Case object, but the UI does not create a Case either...