• P360 Support User
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi 
My trigger is on field update to send out email.
It is working fine if i update the field manually but not working when field is updated with an approval process.
when i check in debug log its is creating an email send record.

check_approval__c this field is getting true when approval flow is completed.

Below is the code, 
trigger SendEmailOnMeeting on Meeting_Resource_Request__c (after update) {
    
    
    for(Meeting_Resource_Request__c mr : trigger.new){
                    Meeting_Resource_Request__c old = trigger.oldMap.get(mr.Id); // get old record from oldMap

        if(mr.check_approval__c== True){
        
        system.debug('enter');
            //Get your document from document Object
            List<Document> docList = [Select Id, Name, Body, ContentType, DeveloperName, Type From Document limit 3];
            List<Messaging.EmailFileAttachment> fileList= new List<Messaging.EmailFileAttachment>();
            for(Document doc:docList)
            {
            
            //Create Email file attachment from document
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType(doc.ContentType);
            attach.setFileName(doc.DeveloperName+'.'+doc.Type);
            attach.setInline(false);
            attach.Body = doc.Body;
              fileList.add(attach);  
              system.debug(fileList);
            }
            //Apex Single email message
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setUseSignature(false);
            system.debug(mr.Email_of_organizer__c);
            mail.setToAddresses(new String[] {mr.Email_of_organizer__c});//Set To Email Address
            
            mail.setSubject('Test Email With Attachment');//Set Subject
            mail.setHtmlBody('Please find the attachment.');//Set HTML Body
            mail.setFileAttachments(fileList);//Set File Attachment
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });//Send Email
            system.debug('exit');
           
        }
    }

}
Hi 
My trigger is on field update to send out email.
It is working fine if i update the field manually but not working when field is updated with an approval process.
when i check in debug log its is creating an email send record.

check_approval__c this field is getting true when approval flow is completed.

Below is the code, 
trigger SendEmailOnMeeting on Meeting_Resource_Request__c (after update) {
    
    
    for(Meeting_Resource_Request__c mr : trigger.new){
                    Meeting_Resource_Request__c old = trigger.oldMap.get(mr.Id); // get old record from oldMap

        if(mr.check_approval__c== True){
        
        system.debug('enter');
            //Get your document from document Object
            List<Document> docList = [Select Id, Name, Body, ContentType, DeveloperName, Type From Document limit 3];
            List<Messaging.EmailFileAttachment> fileList= new List<Messaging.EmailFileAttachment>();
            for(Document doc:docList)
            {
            
            //Create Email file attachment from document
            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType(doc.ContentType);
            attach.setFileName(doc.DeveloperName+'.'+doc.Type);
            attach.setInline(false);
            attach.Body = doc.Body;
              fileList.add(attach);  
              system.debug(fileList);
            }
            //Apex Single email message
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setUseSignature(false);
            system.debug(mr.Email_of_organizer__c);
            mail.setToAddresses(new String[] {mr.Email_of_organizer__c});//Set To Email Address
            
            mail.setSubject('Test Email With Attachment');//Set Subject
            mail.setHtmlBody('Please find the attachment.');//Set HTML Body
            mail.setFileAttachments(fileList);//Set File Attachment
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });//Send Email
            system.debug('exit');
           
        }
    }

}