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
cruttley2cruttley2 

How to send an email that includes attachments from Notes& Attachments?

I would like to have a button on a custom object, that when clicked, will open the standard Send Email window, but automatically include all the attachments that were attached to that instance of the custom object.

The user can then remove any attachments they dont want, or add other attachments, then send the email.

(I understand that perhaps documents should be stored in Libraries or Documents folders, and not in Notes&Attachments, but that is another discussion).

I am not a developer, but if there is a solution for this I would try and implement it. All help greatly appreciated!
AshwaniAshwani
You can use Messaging.EmailFileAttachment class
// fetch attachments for Opportunity
   List<Attachment> attList = [SELECT id, Name, body, ContentType FROM Attachment WHERE ParentId = : case.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);
     // so on....
     efaList.add(efa);
   }

    // Attach files to email instance
    email.setFileAttachments(efaList);