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
cloudSavvyProgcloudSavvyProg 

Email not sent from Trigger.

I have a custom object trigger that has a logic of sending emails to ids based on criteria. It uses email template and org wide address.

So when the record is inserted, the trigger should send emails. I am not recieving any emails. Any idea how to solve this? 

The code is as follows.

Messaging.SingleEmailMessage mail = Messaging.renderStoredEmailTemplate(emailtemplate.Id, UserInfo.getUserId(), record.Id);
                        List<string> toAddress = new List<string>{"valid address"};
                        mail.setToAddresses(toAddress);
                        mail.setSubject('test');
                        mail.setOrgWideEmailAddressId(owa.Id);
                        mail.setSaveAsActivity(false);
                        mail.setUseSignature(false);
allmsg.add(mail);  
Messaging.sendEmail(allmsg,false);

The above code is in @future method.

Not receiving any emails? how to resolve this?  is there any configuration needs to made in SF?
Musunuru SurekhaMusunuru Surekha
Hello,

Did you check the "Deliverability" option under "Email Administration"?
 
cloudSavvyProgcloudSavvyProg
Yes, it’s set to All Emails.
Steven HodgkinsonSteven Hodgkinson
@cloudSavvyProg I am facing the same problem did you manage to resolve this? 
HijlkoHijlko
Just saw your problem today (over 1 year later) and hope it's already solved. I think it's because the trigger probably runs on BEFORE(?) insert, then there is no record.ID yet. The email can be triggered on AFTER insert