You need to sign in to do that
Don't have an account?
baller4life7
Sending many single emails with 1 sendEmail() execution
global class OpportunityStatusReport implements Schedulable { public static final String EMAIL_TEMPLATE_ID = '00XP0000000HucQ'; public List<AggregateResult> openOpps = new List<AggregateResult>(); public Messaging.SingleEmailMessage [] singleEmails = new List<Messaging.SingleEmailMessage>(); public Messaging.Email[] allEmails = new List<Messaging.Email>(); global void execute (SchedulableContext SC) { // Gets the list of the opportunity status report recipients. Only active users with open opportunities will get an email. openOpps = [ SELECT o.OwnerId FROM Opportunity o WHERE o.Owner.isActive = true AND o.isClosed = false GROUP BY o.OwnerId ]; if(openOpps.size() > 0) { // Creates a personalized email for each recipient for (AggregateResult opp : openOpps) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId((String)opp.get('OwnerId')); mail.setTemplateId(EMAIL_TEMPLATE_ID); mail.setSaveAsActivity(false); singleEmails.add(mail); } for( Integer i = 0; i < singleEmails.size(); i++ ) { allEmails.add(singleEmails.get(i)); } if (allEmails.size() > 0) { Messaging.sendEmail( allEmails ); } } } }
System.UnexpectedException: Not Serializable: LIST<Messaging.Email>
---
Hey guys,
how can I fix the exception? (Making the list transient doesn't solve the problem)
Thx for your help
Josh
Hi Josh,
I believe moving the
variables inside the execute block , will solve your problem.
Then the variables, are destroyed after the execute method returns and need not be persisted across invocations.
All Answers
Hi Josh,
Not sure if we can resolve your issue, but if you want to send emails from batch then I have posted some code here :
http://forceguru.blogspot.com/2011/03/how-to-send-more-than-10-e-mails.html
Hope this will help.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi Josh,
I believe moving the
variables inside the execute block , will solve your problem.
Then the variables, are destroyed after the execute method returns and need not be persisted across invocations.
Thanks guys! Sham_1's solution worked for me. I also had to remove the public keywords...