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
KD123456KD123456 

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});
//        }
    }
}

 

 

anil 007anil 007

 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

 

 

 

 

KD123456KD123456

Hi,

 

It would work but is there a way to include the attachments in the case with that notification email.

 

Thanks

KD

TrimbleAgTrimbleAg

Hey KD,

 

Did you ever find a solution for this? I am looking for the same thing.

 

PB