+ Start a Discussion
Makam RuthvikMakam Ruthvik 

attach file that is on a record to email template

Hi All,

I have a pdf attached to files in Order records{PDF has a unique name so have to query based on it's name}. How to query it from the Order record and attach it to Classic Email Template. Please help me here. Thanks in Advance
Garcia MichelGarcia Michel
Google refuses to show images with data url in Gmail's web interface. It's a known problem (in Google's view a security measure) for a long time highly criticized.
The good news is that you have another option except for using external images.
Using an inline attachment with a Content-ID works with Gmail.
After adding your images as inline attachments you'll need to point CID URLs instead of Data URLs in the html body.
There are plenty of modern libraries that will allow you to send emails with inline attachments easily. But I wrote a sample script in VBScript with CDO library, ready to use if you have a box Windows 2000+ installed.
Let's prepare the test environment.

DGCustomerFirst (https://www.dgcustomerfirst.org/)
Lukesh KarmoreLukesh Karmore
Hello Makam Ruthvik
you can query documents/files from org using ContentdocumentLink  ok i'll provide you a sample Query ,Mark the best answer ,so it helps other.
ContentDocumentLink cdl:[SELECT LinkedEntityId,ContentdocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN:acctIds])
Where LinkedEntityId is the Id of records where your document is attached && ContentdocumentId  is teh id of your document .

and another  how to send  document in email in (messaging.SingleEmailmessage)
please refer below code to ger some idea 

list<contentVersion> covVer=[SELECT id,contentDocumentId,Title,versionData FROM contentVersion WHERE contentDocumentId=:con.contentDocumentId];
        Messaging.singleEmailMessage mail=new  Messaging.singleEmailMessage();
        list<string> toaddress=new list<string>();
        mail.setSubject('your Subject');
        mail.setPlainTextBody('This is first email attachment');
        messaging.EmailFileAttachment efa=new messaging.EmailFileAttachment();
        mail.setFileAttachments(new messaging.EmailFileAttachment[]{efa});
Thank You 

Mark the best answer ,so it helps other.
Makam RuthvikMakam Ruthvik
Hi Lukesh,

Thanks for the above information but how to add it my classic email template. I have already a vf page that goes from that template and need to add an attachment. I want to add the attachment to classic email template basically. Can you please help me here.