1

I need to assign the case (created through email-to-case) to the account owner if certain condition satisfies. In the before insert of the trigger event, I assign the newly created cases' owner id , however owner doesn't get updated for the case. I checked the debug log and see in the before insert event account is null.

I put the same code in before update and it's working fine , obviously account is not null in before update when case is created through email to case. I checked the debug log and couldn't find why account will be null in before insert, but not in before update. Neither, I can find any automated process which will populate account on the case. I set the field tracking for account on case and see , 1) Case is created first 2) Account on case is updated if the case is created from the email and the contact->account exists with that email id.

I wanted to know, if this is expected behaviour? Or am I missing some automated process in my org which may be updating account on the case? If this is expected, is there any documentation around it?

1 Answer 1

2

I'm not sure where, or if, this is documented, but I do know that this is normal behavior. The Contact and Account will not be resolved until the after-insert phase of the trigger process. In fact, the OwnerId field will be "wrong" in the after-insert trigger phase as well, because assignment rules don't run until later. You could use a Process Builder/Autolaunched Flow to make sure that you have access to the correct owner/contact/account values while creating the record.

3
  • I need to execute assignment rule as well if that criteria doesn't satisfy , else assign the owner to account owner in the before update and set the boolean flag and check this flag while evaluating the criteria of the assignment rule. Commented May 11, 2020 at 11:58
  • @ManishAnand Assignment rule execution has already been decided by that point. You can use a recursive update from a process builder to determine if additional actions are needed, but your use case isn't easy to configure.
    – sfdcfox
    Commented May 11, 2020 at 12:09
  • @sfdcbox:- Using before update, I tested both the scenarios (updating case owner through before update trigger as well as assignment rule) and both seems to be working fine. Commented May 11, 2020 at 12:14

You must log in to answer this question.

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