function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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!
Frank MerzFrank Merz
Had the same problem with case owners being overwritten by standard case owner after changing case owner by trigger or flow. The solution suggested by Richy Eva1 absolutely worked for me.

1. Add a new step to the existing case assignment rule (or create a new rule, if there isn't already one).
2. Give the new step the order number "number of existing entries + 1" (e.g. if you have 1 entry already, type in "2" as order number for the new step).
3. In the new step, fill the criteria fields with "Case: Case Owner" / equals / "name of owner not to be overwritten" (replace "name of owner not to be overwritten" with the owner name that should not be overwritten with standard case owner; DO NOT use the API names here, but fill in the owner names, e.g. if you want to insert a queue with the name "Test Queue" and API name "Test_Queue" as value for the criteria mentioned above, use the name "Test Queue").
4. Repeat step 3 until all case owners you don't want to be overwritten by standard case owner are listed.
5. Add a custom filter logic for all listed case owners with the "OR" operator, e.g. if you have three criteria fields/owners in your list, type in "1 OR 2 OR 3" in the filter logic field.
6. Final step: It's essential that the checkbox "Do Not Reassign Owner" is checked, because the case owners in the criteria list aren't overwritten with the standard case owner ONLY when this checkbox is checked.
7. Save the new step so that it will become active.

Thanks again Richy Eva1 for your solution :-)
SouvikSomeSouvikSome
Create an assignment rule as per your origin/ conditions for the email-to-case scenario. Check the Do Not Reassign Owner checkbox. So, it will not trigger the support default owner and it will retain the Case Owner assignment from before insert trigger -

User-added image