You need to sign in to do that
Don't have an account?
Eduard 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.
Thanks,
Eduard
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.
Thanks,
Eduard
https://help.salesforce.com/articleView?id=000199222&type=1
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.