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
Julie Steinloski 5Julie Steinloski 5 

automated email an attachment from related list on case

Hi ... We have customers who send documents for review using email-to-case.  The documents come as email attachments which land on the case - attachment related list.  We would like to send an automated email referencing the attached document using workflow rules.  The workflow rule works with the exception of including the document in the reply.  Here's what I'm using for my VF page, but it's not pulling the attachments

<messaging:emailTemplate subject="Testing Attachment Lists" recipientType="Contact" relatedToType="Case">
<messaging:plainTextEmailBody >
Thank you for your email regarding the attached document(s).  We will review your document and reply shortly.  
<apex:relatedList list="Attachments" />
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
GauravGargGauravGarg
Hi Julie,

You need to use Messaging.singleEmailMessage class with following values:
  • Object record id
  • Receipient Id
  • Attachment Id
  • Do you want to save email as history. 
Below are the sample of above feature:
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
// Set recipients to two contact IDs.
// Replace IDs with valid record IDs in your org.
message.toAddresses = new String[] { '003D000000QDexS', '003D000000QDfW5' };
message.optOutPolicy = 'FILTER';
message.subject = 'Opt Out Test Message';
message.setEntityAttachments(List<Attachments>);  // Add list of attachments. 
message.plainTextBody = 'This is the message body.';
Messaging.SingleEmailMessage[] messages = 
    new List<Messaging.SingleEmailMessage> {message};
         Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
    System.debug('The email was sent successfully.');
} else {
    System.debug('The email failed to send: '
          + results[0].errors[0].message);
}

Hope this will help. 

Thanks,
Gaurav
Skype: gaurav62990