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
jaishrijaishri 

When a case is closed send an email to the case contact with attachment that is associated to the case through trigger can anyone helpe

Best Answer chosen by jaishri
SwethaSwetha (Salesforce Developers) 
HI JayS,
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

SwethaSwetha (Salesforce Developers) 
HI JayS,
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
This was selected as the best answer
CharuDuttCharuDutt
Hii JayS
Try Below Trigger
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);
        }


}
Please Mark It As best Answer If It Helps
Thank You!
jaishrijaishri
Hi CharuDutt,
  your trigger is working but it is taking a same attachement in every email which is sending to case contact