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
mattdarnoldmattdarnold 

Batch Apex - finish method issue

I am running a batch apex class that is scheduled to run periodically throughout the week. (It implements the schedulable interface.) As part of the finish method, I am attempting to create and send an email alerting users that the batch class has completed running. The code compiles / saves fine in the Sandbox - and my unit tests run fine in the Sandbox as well. However, we I go to deploy I get the following error that disappears if I comment out the email code:

System.Exception: Error processing messages

Here is the code within the finish method. Any help / thoughts are appreciated.

Thanks
-- Matt

 

global void finish(Database.BatchableContext BC){

List<String> toAddresses = new List<String>();
// Add email string to List
toAddresses.add('marnold@communispace.com');
String subject = 'Batch class run complete';
String body = '';

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(toAddresses);

mail.setSenderDisplayName('Salesforce Outbound Notification');
mail.setSubject(subject);
mail.setPlainTextBody(body);
mail.setUseSignature(false);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}

 

 

 

JimRaeJimRae

Did this ever get resolved for you?  I am getting the same error when I try to deploy a scheduled apex class.

Marty Y. ChangMarty Y. Chang

Hello, Matt,

 

Is it possible that the root of your error is that you're calling Messaging.sendEmail() with an incorrect signature? Messaging.sendEmail() expects a Messaging.Email[] parameter, but you actually supplied a Messaging.SingleEmailMessage[] parameter.

 

Try...

 

 

Messaging.sendEmail(new Messaging.Email[] { mail });

Let me know if that helps or if you reached another resolution for the issue.  Thanks!

 

Marty...

 

Marty Y. ChangMarty Y. Chang

Hello, Jim,

 

I'm not sure what your code looks like, but I actually came to this thread because I was encountering the same "System.Exception: Error processing messages" error when running my unit tests.

 

In my case, I realized from some debugging that my SOQL query used a null pointer in the WHERE clause.  The gist of the WHERE clause was...

 

 

SELECT Id
FROM MyObject__c
WHERE MyDate__c < :referenceDate.addDays(1)

I would get the weird error message when referenceDate == null, but when referenceDate was a valid Date then the code executes with no problems.

 

 

Marty...

Scott.MScott.M

I'm getting this error as well. It's very frustrating. It seems like the batch testing framework is failing when there's an exception in the execute method during the test. It's especially frustrating because the actuall error doesn't get sent so it's back to primitive debuging techniques

Mat KwokMat Kwok

Has anyone had any luck with this issue? I'm receiving this message while running tests on a Schedulable/Batch class.

jrojasjrojas

if you is running the implemetaion into a sandbox, for send e-mails you need:

see, in Setup, E-mail Administration, Deliverability in your organization, into Access to Send Email side, verify the field Access level select all Email option and save.