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
Eduard PaninEduard Panin 

When sending an email with attachments (Messaging.SingleEmailMessage), the attachments are not visible in activity history

Hello, 

Issue: I don't see the attachment in EmailMessage via activity history. 

I use a simple method of sending a single email.

String whoId = // Some Contact id
String whatId = // Some Account Id
Messaging.SingleEmailMessage result = new Messaging.SingleEmailMessage();
result.setTreatTargetObjectAsRecipient(false);
result.setTreatBodiesAsTemplate(true);
result.setTargetObjectId(whoId);
result.setWhatId(whatId);
result.setSubject(subject);
result.setHtmlBody(body);

List<SObject> contents = Database.Query('SELECT VersionData, PathOnClient FROM ContentVersion WHERE ContentDocumentId');
Messaging.EmailFileAttachment[] attachments = new Messaging.EmailFileAttachment[] {};

Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName((String)contents[0].get('PathOnClient'));
attachment.setBody((Blob)contents[0].get('VersionData'));
attachments.add(attachment);

result.setFileAttachments(attachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{result});

The email with attachment send successfully but I don't see the attachment in the Activity history as
an attachment for current email. It does not depend on ContentDocument because I tried to do it without it. 
Let me know what I am doing wrong. Maybe it is a platform bug or limitation. 
User-added image

Thanks,
Eduard
Waqar Hussain SFWaqar Hussain SF
Eduard PaninEduard Panin
Hello Waqar.
Thanks for the article. I have checked it and setup.
Unfortunately, it doesn't help in my case. Seems it is related with Messaging.sendEmail option in Apex.