You need to sign in to do that
Don't have an account?
P360 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');
}
}
}
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');
}
}
}
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
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.