You need to sign in to do that
Don't have an account?
bathy
Apex trigger to send an email with an attachment from the Attachemnts and Notes Section of the Object's Related list
hi Guys,
I have a requirement to send an email alert with a PDF FIle attached to that record when a particular codnition is met . Can nayone please help with the Trigger code for this?
I have a requirement to send an email alert with a PDF FIle attached to that record when a particular codnition is met . Can nayone please help with the Trigger code for this?
Hi Bathy, you can reuse the code, 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.
All Answers
Hi Bathy, you can reuse the code, 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.