You need to sign in to do that
Don't have an account?
KD123456
Trigger for including attachments with notification email
Hi,
I am trying to send a notification email whenever a case is created with the attachments that were included in the email which created the case. I am able to get the code developed and it sends the notification email but the attachment is not getting through please help
trigger EmailNotification on Case (after insert, after update) { for(Case c : system.Trigger.New) { // if(c.Notified__c == true) { List<EmailTemplate> listET = new List<EmailTemplate>(); List<User> listOwner = new List<User>(); List<Attachment> listAttch = new List<Attachment>(); listET = [select Id, Name, Body, Subject from EmailTemplate where Name = 'Support: Case Assignment Notification']; listOwner = [select Id, Name, Email from User where Id = : c.OwnerId]; listAttch = [select Id, Name, Body, ParentId, ContentType from Attachment where ParentId = : c.Id]; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); Messaging.EmailFileAttachment emailAttch = new Messaging.EmailFileAttachment(); if(listAttch.size() > 0) { for(integer i = 0; i < listattch.size(); i++) { emailAttch.setFileName(listAttch[i].Name); emailAttch.setBody(listAttch[i].Body); emailAttch.setContentType(listAttch[i].ContentType); } mail.setFileAttachments(new Messaging.EmailFileAttachment[] {emailAttch}); } string[] toadresses; for(integer j = 0; j < listOwner.size(); j++) { toadresses = new string[] {listOwner[j].Email}; } mail.setToAddresses(toadresses); mail.setReplyTo('spprtemail5@gmail.com'); mail.setSenderDisplayName('SupportEmail'); for(integer k = 0; k < listET.size(); k++) { mail.setSubject(listET[k].Subject); mail.setHtmlBody(listET[k].Body); } Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); // } } }
HIII
email notification can be achieved by using workflows
try this sample;
1)create a workflow rule for case object
2) in rule criteria write conditon for case.origin equals to email
3)add workflow action for email alert
hope it works
Hi,
It would work but is there a way to include the attachments in the case with that notification email.
Thanks
KD
Hey KD,
Did you ever find a solution for this? I am looking for the same thing.
PB