+ Start a Discussion
Sachin10Sachin10 

Default Case Owner Overriding Trigger Assignment

Hi All,
I have a trigger on attachment object to update the case owner based on the attachment type.
But the owner is being reassigned to case default owner (under Support Settings)

I have tried the dml options but it didn't work.
Any pointers/workarounds will be highly appreciated.
Many thanks in advance
Arun MKArun MK
Hi,

You can make use of DMLOptions assignmentRuleHeader

Can you try the following:
trigger X on attachment (after insert) {
    Case[] cases = new Case[0];
    for(Attachment record: Trigger.new) {
         if(someCondition) {
             cases.add(new Case(id = ..., ownerid = ....));
         }
    }
    Database.DMLOptions options = new Database.DMLOptions();
    options.assignmentRuleHeader.useDefaultRule = false;
    cases.setOptions(options);
    update cases;
}

 
Sachin10Sachin10
@Arun Thanks for your reply.
As mentioned, I have already tried that. But it didn't work. 
The Support Setting default case owner is overriding whatever I give in the code.
I can see in the case history the owner being assigned by the trigger,but it is being overriden by theCase Default owner in the support setting.

Any pointers will be helpful
Many Thanks
Arun MKArun MK
If that is not working, can you try this 

create a check box in case “Owner updated by attachment type?”

set this checkbox to true on the attachment trigger when you set the owner. 

In the assignment rule entry criteria, Check if the ”Owner updated by attachment type?” is false. By this way you can exclude the case from trigerring the assignment rule. Let me know if you are still facing issue
Sachin10Sachin10
@Arun, Thanks for your reply.
I have tried your suggestion, but that didn't work.
To give you more context, I'm using Email-to-Case functionality to create the Case.

The checkbox field “Owner updated by attachment type?” is getting set to true, 
The owner is also getting set but it is getting overriden NOT by ASSIGNMENT RULES, but by SUPPORT SETTING DEFAULT CASE OWNER.

I tried deleting all the assignment rules, It didn't work then also.
Unfortunately I cannot leave this Support Setting Default Case Owner blank.
It is a mandatory field.

Any pointers will be helpful.

Many Thanks
 
Arun MKArun MK
Can you please confirm me that you have done the following
  1. set the checkbox to true,
  2. excluded the case from assignment rule by checking checkbox is not true
  3. Used the following code
Database.DMLOptions options = new Database.DMLOptions();
    options.assignmentRuleHeader.useDefaultRule = false;
    cases.setOptions(options);
    insert cases;

 
Sachin10Sachin10
Yes Arun,
I have done all of them.
Infact everything is getting reflected also. But the case owner is getting overridden by the Support Setting.
Not sure how to prevent that from happening.

Many Thanks
Arun MKArun MK
I came across this link. Can you see the solutions mentioned helps

https://salesforce.stackexchange.com/questions/40507/case-default-owner-is-overriding-specified-case-owner
Richy Eva1Richy Eva1
**Updating this comment with a solution I found**

1. create Case assignment rule step,
2. In condition, add- "Case: Case Owner  EQUALS  <new owner to be updated>"  and any condition if needed.
3. Under 'Select the User...' section, mark the checkbox - 'Do Not Reassign Owner'
4. Save.

Now, Default owner will not be updated, whenever you are trying to update owner from the trigger.
Maryanne RenzettiMaryanne Renzetti
Hi Richy! I am facing this now. Can I ask for some clarificaation on your solution here?
2. In condition, add- "Case: Case Owner  EQUALS  <new owner to be updated>"  and any condition if needed.

So you 're adding a condition that the Case Owner equals the original owner (the default owner named in support settings)?

For me, when I click 'Do Not Re-Assign", it blanks out the new owner I have chose in the rule...do you k now how to get around that?
Bernardo Lira 1Bernardo Lira 1
Here's what I tried and worked for me:
  • Create a field "Actual user assigned" in Case
  • Create a trigger that populates that field according to the criteria (in my program, simple round robin)
  • Create a process in PB to
    • Fill the OwnerId with the actual user assigned field
    • Put the actual user assigned to null (optional)
It actually worked for me!
Please feel free to ask me for more details.

Best!