[SalesForce] Case default owner is overriding specified case owner

We have third party form builder tool called Wufoo that creates records on a custom object when a form is submitted. If certain criteria applies, we trigger a case creation and specify who the case owner is.

However, after the Case is created and assigned. Salesforce will auto-assign the Case to the "Default Owner" found in Build > Customize > Cases> Support Settings.

As you can see below the correct owner is assigned, but Salesforce will reassign the record:
enter image description here

To try debugging the issue, I created a case manually and Salesforce will not override the owner.

Does anyone have any suggestions for how I can assign my Case a new owner without Default Owner overriding this?

Best Answer

When creating cases from a trigger, you can specify DMLOptions to prevent the assignment rules from firing. Something like this:

trigger X on Y (after insert) {
    Case[] cases = new Case[0];
    for(Y record: Trigger.new) {
         if(someCondition) {
             cases.add(new Case(...));
         }
    }
    Database.DMLOptions options = new Database.DMLOptions();
    options.assignmentRuleHeader.useDefaultRule = false;
    cases.setOptions(options);
    insert cases;
}

I haven't personally used DMLOptions before, so you may need to tweak this answer a bit.

Related Topic