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
Shane QuiringShane Quiring 

Is there a way to e-mail attachments from Notes and Attachments?

Hi Experts,

Does anyone know of a way to attach files, to an e-mail, from notes and attachments? Instead of downloading the attachement to the hard drive and uploading to the e-mail.

Any help would be greatly appreciated, thank-you.

v/r
Shane Quiring
Best Answer chosen by Shane Quiring
Rahul Sangwan7341Rahul Sangwan7341
yes...you are correct........you will write a trigger on after update and check your condition whether to send email or not and in this trigger you will get the id of Parent Record. Then you have to create instance of Email and set all parameters and attach your attachment with Email instance as written in code. 

Please mark this as best answer if it really helps you.

All Answers

Rahul Sangwan7341Rahul Sangwan7341
Hi Shane , you can do it through code(trigger), based on some button like take Send Email button make a field update and based on your field update send the Email with attachment.

//Put your record id in ParentId
List<Attachment> attList = [SELECT id, Name, body, ContentType FROM Attachment WHERE ParentId = : opp.id];
// List of attachments handler
Messaging.EmailFileAttachment[] efaList = new Messaging.EmailFileAttachment();
for(Attachment att : attList)
{ // Create the email attachment Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.Name);
efa.setBody(att.body);
efa.setContentType(att.ContentType);
efa.setInline(false);
efaList.add(efa); }
// Attach files to email instance
email.setFileAttachments(efaList);

Please mark this as Best answer if it helps you and let me know if you finding any difficulty in this.


 
Shane QuiringShane Quiring
Hi rahul Kumar 29, 

Thank-you for the information, this is great but I do have a couple of questions

Forgive my ingnorance here, I am extremly new to APEX and coding:
1. You had stated that I can "based on some button like take Send Email button". Will also include the "Attach File" button on the e-mail interface?
2. How do I base it off a button, like "Send an Email"?

Thank-you for your assistance.
Rahul Sangwan7341Rahul Sangwan7341
Hi Shane, I didn't get you..................what I understood is you will send email based on particular record and in this email you will send the attachments of particular record in that email, am i right? 
And that particular scenarion can be achived by code which i shared.
Shane QuiringShane Quiring
Hi rahul Kumar 29,

Yes you are correct. Great!. Correct me if I am wrong; in the coding that you had provided, all I have to do is adjust this part of the coding:

//Put your record id in ParentId
List<Attachment> attList = [SELECT id, Name, body, ContentType FROM Attachment WHERE ParentId = : opp.id];

Where if I wanted to have run on the Account object I would use Account.id, etc. ... Correct?
Which would mean that if I wanted use this for any object, I would have to change the ParentId to the specfic object, in essence creating one trigger per object. Correct?

Thank-you for your assistance.

v/r
Shane
Rahul Sangwan7341Rahul Sangwan7341
yes...you are correct........you will write a trigger on after update and check your condition whether to send email or not and in this trigger you will get the id of Parent Record. Then you have to create instance of Email and set all parameters and attach your attachment with Email instance as written in code. 

Please mark this as best answer if it really helps you.
This was selected as the best answer
SalmanSalman
Hii Shane Quiring,

Can you please check this application for Email Attachments,

MassMailer Docs is the best way to store and mass email your Salesforce files to contacts or leads
Attach files to Salesforce objects and mass email them as file attachments to your contacts or leads in one go.

For this, you might need to visit and play with this app -Massmailer Docs

For more details about massmailer docs please click here Link