• Vivek Warrier
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I've been working on an email trigger which will include the attachments tied to the record when the email is sent. Below is the trigger. The email gets sent however the attachments aren't included for some reason. Is there something missing?
 
trigger Send_ChecklistEmail on Food_Safety_Section_Worksheet__c (after update, before insert) {


    for(Food_Safety_Section_Worksheet__c SC : trigger.new){
        Food_Safety_Section_Worksheet__c oldSC = Trigger.oldMap.get(SC.Id);
        if(SC.Send_Email__c == true && SC.Send_Email__c != oldSC.Send_Email__c){
            
            //Retrieve Email template
            EmailTemplate et=[Select id from EmailTemplate where name=: 'Food Safety Email'];
            
            //Create email list
            List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();            
            
            //Create message
            Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
            //add template
            singlemail.setTemplateId(et.Id);
            //set target object for merge fields
            singlemail.setTargetObjectId(SC.OwnerId);
            singlemail.setWhatId(SC.Id);
            //set to save as activity or not
            singlemail.setSaveAsActivity(false);
            
            //add address's that you are sending the email to
            List<String> sendTo = new List<String>();
            String owneremail = [select Email from User where Id = :SC.OwnerId].Email;
            sendTo.add(SC.Franchisee_Email__c);
            sendTo.add(owneremail);
            
            //set addresses
            singlemail.setToAddresses(sendTo);
            
            //add mail
            emails.add(singlemail);
        
            //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength, ContentType from Attachment where ParentId = : SC.Id])
        {
        // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        efa.setContentType(a.ContentType);
        efa.setInline(false);
        fileAttachments.add(efa);
        }
        singlemail.setFileAttachments(fileAttachments);

        //Send email
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{singlemail});
 }  
}
}

 
  • June 27, 2019
  • Like
  • 0
Hello,

I want to re-create a schedule job and am unable to. This is the error that it keeps throwing me "You must select an Apex class that has a parameterless constructor."

Can someone tell me why it is throwing this or if there is a way I can retreive the schedule job?

Can I create  a change set for a schedule job/

Thank you.