function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger CaseClosedTrigger on Case (After Update) { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); map<String,string> ContactEmailSet = new map<String,string>(); Set<Id> CaseId = new Set<Id>(); For(Case oCase : trigger.new){ if(oCase.IsClosed && oCase.IsClosed != trigger.oldMap.get(oCase.id).IsClosed){ ContactEmailSet.put(oCase.Id,oCase.ContactEmail); } } list<Attachment> lstCase = [SELECT Id, ContentType, Body, Name FROM Attachment where ParentId in :ContactEmailSet.Keyset()]; List<String> Email = new List<String>(); Email = ContactEmailSet.values(); for(Attachment Att : lstCase){ String Contype = Att.ContentType.substringAfter('/'); Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); attach.setContentType(Att.ContentType); attach.setFileName(Att.Name+'.'+Contype); attach.setInline(false); attach.Body = Att.Body; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSubject('Case Isclosed'); String body = 'Dear Record Owner Case Isclosed '; mail.setToAddresses(Email); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); mail.setHtmlBody(body); mails.add(mail); } }
The code from below links should help you get started. You will need to customize as per your requirement
Trigger to send a email when the case status is closed
https://developer.salesforce.com/forums/?id=9062I000000IYNNQA4
Code to include attachments to the email
https://salesforce.stackexchange.com/questions/115378/trigger-to-send-email-with-related-attachments
Happy to help if you are stuck somewhere. If this information helps, please mark the answer as best. Thank you
All Answers
The code from below links should help you get started. You will need to customize as per your requirement
Trigger to send a email when the case status is closed
https://developer.salesforce.com/forums/?id=9062I000000IYNNQA4
Code to include attachments to the email
https://salesforce.stackexchange.com/questions/115378/trigger-to-send-email-with-related-attachments
Happy to help if you are stuck somewhere. If this information helps, please mark the answer as best. Thank you
Try Below Trigger Please Mark It As best Answer If It Helps
Thank You!
your trigger is working but it is taking a same attachement in every email which is sending to case contact