I have a simple batch job that is used to send a notification email. I'm testing in a partial sandbox, but the email is not coming thru. Here is what I've checked:
- I verified that deliverability is set to "All Email"
- I checked the limits in workbench which shows I have 4993 out of 5000 single email limits remaining
- I've debugged the code and the sendEmailResults shows the email was sent successfully
- I've also tested deliverability and verified that the emails from Salesforce
come
thru to my email address and I received the emails
Here is the code:
global Database.querylocator start(Database.BatchableContext BC){
return Database.getQueryLocator('select Id, StageName, Owner.Email from Opportunity where Role_Record_Count__c = 0 AND CloseDate < NEXT_90_DAYS AND Project_Start_Date__c < NEXT_90_DAYS AND (StageName = \'B - Value Justification\' OR StageName = \'A - Pending Sales\')');
}
global void execute(Database.BatchableContext BC, List<sObject> scope) {
Messaging.SingleEmailMessage emailMsg = new Messaging.SingleEmailMessage();
List<String> toAddresses = new List<String>();
for(Opportunity o : (List<Opportunity>)scope) {
toAddresses.add(o.Owner.Email);
}
system.debug('******************************************** toAddresses ' + toAddresses);
emailMsg.setToAddresses(toAddresses);
emailMsg.setSubject('Test Subject!!');
emailMsg.setPlainTextBody('Hello!!!!!!!!!!This is a test email to test single email message program');
emailMsg.setHtmlBody('Hello!!!!!!!!!!This is a test email to test single email message program');
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {emailMsg};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
System.debug('The email was sent successfully.');
} else {
System.debug('The email failed to send: ' + results[0].errors[0].message);
}
}
global void finish(Database.BatchableContext BC) {
}
Anyone have any idea what might be preventing the email from being sent in a partial sandbox? Is there anything wrong with the code?
@example.com
appended. – Thomas Taylor Aug 19 '19 at 0:15