I'm creating EmailMessage records via DML
EmailMessage createWhatEmail = new EmailMessage(
Subject = 'test'
,Status = '3'
,ToAddress = 'heim@elastify.eu'
,FromAddress = UserInfo.getUserEmail()
,FromName = UserInfo.getFirstName()+' - '+UserInfo.getLastName()
,HtmlBody = 'a body'
,Incoming = false
,MessageDate = DateTime.now()
,RelatedToId = taskWhatId
// ,HasAttachment = true // not possible: Read-Only!
);
insert createWhatEmail;
The attachments I'm assigning like this:
for(ContentVersion cv : attachmentCVs) {
ContentDocumentLink cdl = new ContentDocumentLink(
ContentDocumentId = cv.ContentDocumentId
,LinkedEntityId = createWhatEmail.Id
,ShareType = 'V'
);
attachmentCDLs.add( cdl );
}
But the result is not flawless:
The attachment is shown correctly under the Attachments related list. But the non-writable HasAttachment
field is false
. Hence the paper-clip indicating the attachment isn't show in the Activity Tab under LEX.
Does anyone know a way to make this right?
The result should look more like this: