[SalesForce] Insert Case Apex – Disable Active Assignment Rules

I am trying to insert a case in apex and set the owner to a specific user id.

However active assignment rules are rerouting the case.

In apex, how would I disable the use of active assignment rules upon insert as you can on the default case creation.

In the case history I can see the owner is going to the user id I set, but the assignment rule changes it on creation.

activeCase.OwnerId = createCaseOwnerId;
insert activeCase;

enter image description here

Best Answer

You have to disable the case assignment while inserting. You can do that using DMLOptions.

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= false;

activeCase.OwnerId = createCaseOwnerId;
activeCase.setOptions(dmo);
insert activeCase;
Related Topic