[SalesForce] Case Assignment Rules and Case After Update trigger

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.

Best Answer

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.

Related Topic