Could anyone tell what is the order of execution, when there is a case created from the email-to-case configuration?

I am in the process of differentiating a case to assign a status to it. AFAI tested the sourceId is populated when the case is created via Email-To-Case.

What's the order of execution on sourceId assignment in a Case?

In the before insert trigger the case sourceId is always null. What's the order of execution as I couldn't find it anywhere on the document?

I assume,

When sending an email to the Email Service Address,

  1. Create an Email Message.
  2. Create a Case.
  3. Update the ParentCaseId on Email Message
  4. Update the SourceId on Case.

I was trying to do the below check in the Case before insert trigger, but it didn't work as expected,

if (newCase.sourceId != null) {
    newCase.Status = 'In Progress';

Any idea on this?

  • 3
    the Case is created before the EmalMessage
    – cropredy
    Commented Jan 13, 2023 at 20:12
  • So, it makes sense that the sourceId is null. Commented Jan 13, 2023 at 21:53
  • 1
    i've not specifically tracked when sourceId is set -- writing debug statements in a Case trigger and turning debug on for the E2C user will let you know when it is set
    – cropredy
    Commented Jan 13, 2023 at 22:28

1 Answer 1


The order is follows,

The case is created.
The email message is created with the parentId.
The case sourceId will be populated.
  • So case is created before insert and sourceId populated after insert? Is that correct?
    – eHarazi
    Commented Jan 26 at 13:03
  • 1
    Yes, you can see the behavior by just having a debug statement. Commented Jan 29 at 13:39

You must log in to answer this question.

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