I have a trigger on EmailMessage that is looking at newly inserted emails sent for Email2Case, and parsing the text for certain trigger words and updating the case if found. This has been working, and in the past I have been able to capture debug logs. I believe I set a log on "Automated Processes" in the past.

Today we've added new criteria (via Custom Metadata). The trigger continues to work for the old criteria, but fails (and prevents case creation) for the new criteria. I attempted to obtain debug logs to determine the cause, but have not been able to do so. I have tried the following:

  • Debug Log of type "Automated Processes"
  • Debug Log of type "User" on Sys Admin user who set up Email2Case
  • Debug Log of type "Trigger" on the trigger in question.
  • Checked W20 known issues for debug log issues (running in W20 sandbox)

As noted above, the trigger does work for some inputs, so I know it is running, but I cannot capture any debug logs. How can I capture a log on this trigger when an Email2Case email inserts an EmailMessage?

  • I haven't worked with Email2Case much, but most likely, the logs should be under the user that the Email2Case routing is under. If you go to setup and Case (in classic at least; setup->feature settings->services->email-to-case in lightning), and then Email2Case setting, there should be a list of routing addresses. Whatever routing address you're trying to log, add a debug log on the Case Owner assigned for that routing address. I think that should capture the logs. Not sure if this will work or not though.
    – Roti
    Commented Oct 3, 2019 at 17:25
  • Roti's explanation is what I understand as well. If you're utilizing email service addresses instead of simply email2case, there's also a specified context user for each specific email service you'd be emailing. Commented Oct 3, 2019 at 18:13
  • If I'm not mistaken, you can go to the Dev Console and select the trigger itself and any relevant classes it calls of importance to you and set overrides on the debug log settings for the trigger and classes. I think that should allow you to retrieve what you want to see. I'm not in a production org today to be able to test this.
    – crmprogdev
    Commented Oct 3, 2019 at 18:34
  • @Roti The Case Owner for the routing address is a Queue, which cannot be traced to produce logs. Given that a Queue is a possible option, I doubt that the process runs as the assigned case owner. I am debugging the user who created the routing, but that isn't working. Commented Oct 3, 2019 at 18:55
  • @crmprogdev. Doesn't work. Seems that trace override simply changes the log level for that particular class/trigger, but won't capture logs on that class unless the user being traced enters it. Commented Oct 3, 2019 at 19:03

1 Answer 1


The running user for Email to Case is found in Setup | Customize | Cases | Support Settings under the field Automated Case User if you are using On-Demand E2C

The user listed in the Case History related list for automated case changes from: • Assignment rules • Escalation rules • On-Demand Email-to-Case • Cases logged in the Self-Service portal

So, you will need to enable debug logging for that user.

If you are using agent-based E2C, the running user would be configured in the E2C agent but should be obvious from looking at the Case Field History related list

However, if you haven't configured a user for the Automated Case User, you will need to

  • I found Setup > Customize > Cases > Support Settings, which lists Automated Case User as "System". Successful E2C cases are owned by System, which appears to be a pseudo-user for which I cannot set a trace flag. I thought that adding a Trace Flag of type "Automated Processes" would capture such things, but it is not currently working for me. Commented Oct 3, 2019 at 19:02
  • 1
    @JasonClark - I guess this is why in every org I have ever worked in that I establish a headless user for this very reason :-)
    – cropredy
    Commented Oct 3, 2019 at 19:06
  • I think you are correct :) - I swapped "system" for a real user, and was able to get the logs. I'm going to amend your answer with those details and accept. Thanks! Commented Oct 3, 2019 at 19:13
  • Jason - see updated answer for an alternative
    – cropredy
    Commented Oct 3, 2019 at 19:15

You must log in to answer this question.

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