You need to sign in to do that
Don't have an account?
Sending Email Template with Schedule Apex
I'm trying to send an automatic email with Schedule Apex Code. Still learning Apex. The class seems to complile fine:
Global class SendOpenCasesEmail_CompanyX implements Schedulable{
global void execute (SchedulableContext SC){
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId('0035000000d0APT'); //email recipient id
mail.setTemplateId('00X500000013ngY'); //email template id
String[] bccaddress = new String[]{'paulmac106@gmail.com'};
mail.setBccAddresses(bccaddress);
mail.setWhatID('0015000000KJImA'); //account id (show cases for this account)
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
But when the sceduler tries to run the job I get this email:
Apex script unhandled exception by user/organization: 00550000001Esxxx/00D500000007xxx
Scheduled job 'SendVal' threw unhandled exception.
caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null: []
Class.SendOpenCasesEmail_CompanyX.execute: line 12, column 2 External entry point
Any help with what I'm doing wrong would be greatly appreciated.
thanks!!
I solved this issue by removing the apex:image tag in my email template. Not the best solution, as I wanted to use a company logo in the email. However, I am now able to schedule the email.
All Answers
If there is any more information I can provide, please let me know. I'm sure there must a simple solution to this.
thanks!
Hi Paul, have you verified that the related record to "0035000000d0APT" has an email address asociated?
Hi Danny,
As a test I was using my contactid, which I know does have a valid email address. Any other thoughts? I'm sure it's something small I'm missing.
thanks!
I solved this issue by removing the apex:image tag in my email template. Not the best solution, as I wanted to use a company logo in the email. However, I am now able to schedule the email.
Hi,
I have the same requirement that you have. I used the code that you have posted here. I have commneted out the "mail.setTargetObjectId" and "mail.setWhatID('0015000000KJImA')" lines and scheduled the class. I am not recieveing any emails.
Do you have any idea? Didi it work for you.
Thanks
SN