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

3 Answers 3


Another possibility:

I look in the dev console and there are no logs after I send the email.

Note that the logs for the inbound email handler will run under the context user set up for the email service, and this user may not be "you" - I know this has tripped me up in the past.


Try to keep allowed email addresses field blank. It should work as you have checked all other point. Also during testing when you reply to email make sure that In To email address correct email address is coming as you have defined in email service. It can also be one of the reason.


From what I can see, all you're doing with the inbound handler is creating a new Lockboxjob__c and then processing Messaging.Inboundemail.TextAttachment to attatch to it. I don't know what a Lockboxjob__c is, but I don't see where you're grabbing the inbound email address or the name of the sender.

Perhaps you removed that section of code on accident when you were modifying your code and that's the source of your problem? Without it, I don't see how you could associate the inbound email with a contact or an account.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .