I have a trigger (AfterUpdate) on the Case object. In here, I am comparing the Owner field in this way:

if((newCase.OwnerId != oldCaseMap.get(newCase.Id).OwnerId) 
     && (tempMap.containsKey(newCase.OwnerId))) {
    //some code

I have Case assignment rules that changes the Case ownership with some specific user/queue(s) based on changes to Status value(s). But, whenever I change the Status value, and Save the record, my Trigger is kicking in. But, as Case Assignment rules fire once the data commits to database, my Owner is remained with older value.

My understanding, Case Assignment rules are firing in current way: After initial commit. But, I am not having any control in terms of Trigger context as the initial commit is completed without any change in Case Ownership, thus my After Update is failing.

If anyone have any workarounds in this scenario, I would really appreciate.

  • What's the code trying to do? Is it something that could be moved to Workflow or PB/Flow? Just trying to use something that occurs after assignment rules in order of execution. Nov 21, 2019 at 23:14
  • It's not about the code within the If() statement, but as my Case Assignment Rules fire later (after initial data commit), my tempMap was unable to contain the newCase's OwnerId. Once the Case Assignment Rules get fire, Ownership gets changed, but AFAIK, we might not be able to get a hold of that DML operation. Nov 21, 2019 at 23:17

2 Answers 2


Assignment rules run after the after triggers, so they can't determine if ownership will change.. Instead, you'll want to consider using a Process Builder to determine if the owner changes, then you can invoke your logic as a Flow or Invocable Method.


I am assuming your question is: why my trigger is failing as my case assignment rule should change the ownership of the case.

That is because the case assignment rule invoked after after-triggers contexts. Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

I would recommend you do the ownership change in before trigger context.

  • 1
    Thanks Wayne, I have seen this. But, I have many queues, and lot of use cases to consider, this trigger implementation should only needs to happen in After Trigger context. Nov 21, 2019 at 23:18
  • I am not fully cross the big picture. In before trigger context, you check case status, if yes, change the ownership. In after trigger, if case ownership changed, then we do sth. I am not sure what tempMap variable do and could you tell me why this implementation only needs to be happen in after trigger context.
    – Wayne Ni
    Nov 21, 2019 at 23:29
  • I am checking if the newMap.ownerId is existed in a map of Custom metadata records. Our application is a pretty huge in regards to configurations. We already have more than 100 of assignment rules too. Case Owner only gets changed in our assignment rules. So, I am trying to see if I can get a hold of DML operation of the Case assignments rule where we get ownership assigned. Nov 21, 2019 at 23:41
  • 1
    If that is case, I don't really think so. Case assignments rule is another seperate thread that I don't think you can manipulate with Apex.
    – Wayne Ni
    Nov 22, 2019 at 0:25

You must log in to answer this question.

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