• prema
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
 when an application submitted it genrerates pdf and saves in notes and attachments now i want to sena an email with pdf attachment to the key contact email.
i tried with below code 
rigger PDFAttachTrigger on Attachment (after insert) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
       
    for(Attachment att : Trigger.new)
    {
        if(att.Name.endsWith('_DTAC_Application__c.pdf') && att.parentId.getSObjectType().getDescribe().getName().equals('DTAC_Application__c'))
        {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {'prema.salesforce@gmail.com'};
            mail.setToAddresses(toAddresses);
            mail.setSubject('DTAC Application Submission Confirmation');
            mail.setSaveAsActivity(false);
            mail.setPlainTextBody('Dear');
           
            Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
            efa.setFileName(att.Name);
            efa.setBody(att.Body);
           
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
            mails.add(mail);
           
           
}
    }
   
Messaging.sendEmail(mails);
}
it is sending email with a pdf attachment to the to address which addressed in  String[] toAddresses = new String[] {'prema.salesforce@gmail.com'};
but i want to use email id from email template  and other fields too

How can i achieve this? 
 
  • February 01, 2022
  • Like
  • 0
Hi,

I would appreciate if you could suggest me a sample code to automate sending pdf through mail.

So the "Notes and Attachment" related list is present in the custom object "Invoice". Whenever a pdf is uploaded in the "Notes and Attachment", an email should be sent to few people. How do I achieve the same ?