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
P360 Support UserP360 Support User 

email not getting send on trigger

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

}
AnudeepAnudeep (Salesforce Developers) 
I suggest reviewing email logs

Quick Find ---> Email Logs---> Request an Email Log.

This can confirm whether an email has been triggered or not and what the underlying issue is
RituSharmaRituSharma
You will be using field update in the approval process. Check if "Re-evaluate Workflow Rules after Field Change" checkbox is checked? If not, enable and then try.
John KlokJohn Klok
Hi

First thing you need to check that trigger are fire or not after approval process complate and second thing you need to check is email deliverability setting make sure it is set to all email.

for check goto setup -> in quick search box type 'Deliverability' ->Access to Send Email (All Email Services) Access level = All email.

Kindly mark this as solved if the reply was helpful.

Thanks.
P360 Support UserP360 Support User
i tried all of the above steps, somehow record is created in debug log but email is not going out, but when i updtae field manually(without approval flow) email is going out.
AnudeepAnudeep (Salesforce Developers) 
That sounds like that 'result' of the Approval Process is not being run. Can you add a Field Update to just that part of the Approval Process so you can make sure the right 'actions' are being run in your tests? Also, do you see any errors in the debug logs?