4

I'm sending a attachment by email as a PDF. Not sure how and when it's happening, but sometimes it seems to change the extension of my pdf to pdf.html. It used to work perfectly before without to specify the contentType, just by mentioning .pdf in the fileName. I tried to add the contentType, but doesn't change anything. Here is a piece of the code I'm using:

Attachment att = [select id, body from Attachment where ParentId = :parentId];
Messaging.EmailFileAttachment emailFileAttachment = new Messaging.EmailFileAttachment();
emailFileAttachment.setFileName('InvoiceXXXXXX.pdf');
emailFileAttachment.setContentType('application/pdf');
emailFileAttachment.setBody(att.Body);
emailFileAttachments.add(emailFileAttachment);
...
singleEmailMessage.setFileAttachments(emailFileAttachments);
...
emails.add(singleEmailMessage);
....
Messaging.sendEmail(emails);

Anyone has ever got the same problem before?

6

It seems that Salesforce converts attachment to html links when total size exceeds 3Mb. This is very annoying.

Source 1

Source 2

  • Is it applicable to Apex email also, or only out of box emails? – Saroj Bera Jun 15 '15 at 6:56
  • I got the problem with Apex email only, not sure if it's the same with email workflow but I believe it's the case for every type of SFDC emails – Cloud Ninja Jun 15 '15 at 6:58
  • In case anyone is wondering, it's still an issue in Spring 17 (API 39) – Christoph Jun 9 '17 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.