I've written an apex email service handler which was working fine two days ago.
I go back to it today, write a test class for it (perhaps modifying some of the apex email handler code along the way, I don't really recall), and now the handler code is not even being executed. I look in the dev console and there are no logs after I send the email.
A couple of things I checked
- Email service is active
- Email address is defined and it is the one that I am sending to
- Allowed email addresses has my email address
Just to emphasize - it is not the code that is wrong. It is not even RUNNING the code in the first place. But I'm sure someone will ask for it, so here it is:
global class FC_LockboxEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
Lockbox_Job__c lockboxJob = new Lockbox_Job__c();
insert lockboxJob;
Attachment[] attachments = new List<Attachment>();
Unidentified_Payment__c[] unidentifiedPayments;
for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
attachments.add(new Attachment(Body = Blob.valueOf(tAttachment.body),
Name = tAttachment.fileName,
parentId = lockboxJob.Id));
// make it a custom setting
if (tAttachment.fileName.startsWithIgnoreCase('unapplied_payments_')) {
List<List<String>> fileRows = FC_CSVReader.readIETFRFC4180CSVFile(Blob.valueOf(tAttachment.body));
FC_CSVRow[] csvRows = parse(fileRows);
unidentifiedPayments = generateUnidentifiedPayments(lockboxJob, csvRows);
}
}
insert attachments;
try {
if (unidentifiedPayments != null) {
insert unidentifiedPayments;
}
result.success = true;
} catch (Exception ex) {
System.debug(LoggingLevel.ERROR, ex.getMessage());
result.success = false;
}
return result;
}
// Some other methods
}