[SalesForce] Disable assignment rule(s) and default owner when using email-to-case

I have a scenario where Case Owner is changed only using Apex code, rather than through assignment rules + default owner. We've been able to make it work for a couple of different Case creation scenarios.

However, when using email-to-case (at least on-demand) the assignment rules + default owner are applied.As this happens after the Apex code we use (an after insert trigger), the Case Owner gets overridden.

We have implemented a workaround, using a "dummy" assignment rule. It works, but it's not a very nice solution. We have some other ideas, but they may require more effort.

We'd like to understand our options. Is it possible to prevent the assignment rules + default owner from being applied in the first place when using email-to-case?

Best Answer

I've solved this as follows

  • Recognize that triggers run before assignment rules and E2C will run assignment rules.
  • In before insert trigger, set custom field Bypass_Assignment_Rules__c to true for those use cases where assignment rules should be bypassed.
  • Create assignment rule (at position 1) that takes any Case with Bypass_Assignment_Rules__c = true and assign to a "in-transit queue"
  • This change in ownership will re-execute your triggers that can detect ownerId = inTransitQueueId and then do the assignment as you desire while also turning Bypass_Assignment_Rules__cto false.