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

apex scheduler

Hi all,

My requirement is to send an email to all the Active accounts on the 1st of every month.I have to use apex Scheduler since it is not possible to do with a workflow.

I started with the below skeleton code and I want to test this using execute anonymous window.

Global class SendEmailAccount implements Schedulable
       global void execute(SchedulableContext sc)
                        public void sendmail()
                        {// Get default sender email address   
                            OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress limit 1];
                            EmailTemplate templateId = [Select id from EmailTemplate where name = 'TemplateName’];
                            List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
                            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                            mail.setToAddresses(new String[] { ‘Senderemailaddress’});
                            System.debug('inside sendmail method');
                              System.debug('inside send mesage method');

I used below code in anonymous window

SendEmailAccount  SEA= new SendEmailAccount();
The code is getting executed but I don't see any email.Any help would be appreciated.Also, can someone let me know how to dynamically insert sender's email address with account email address?
HI Akshara

You cant have more than 10 Messaging.sendEmail() calls in a single transaction.
Check the debug logs. 
Hi Sure@Dream,

Thanks for your input.However,I am making only one call to Messaging.sendEmail()  in this transaction.I don't see any error in the debug logs either
I think I will have to set TargetObjectId