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
paul-lmipaul-lmi 

DMLOptions not triggering Case assignment rule

Hi,

 

I have the following code

 

 

//set the assignment rules to actively route case
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = True;

//fieldsDisabled = true;
Case cse = new Case(
subject = subject,
description = description,
suppliedemail = email,
suppliedname = suppliedname,
product__c = productstring,
operating_system__c = operatingsystemstring,
type = typestring,
lang__c = lang,
origin = 'Email'
);

cse.setOptions(dmo);

system.debug('case info before insert' + cse);
insert cse;

 

 Which "should" trigger the default Case assignment rule, which has one rule

 

(if case.origin = 'email') which is always going toeval to true since i manually set this when inserting it.

 

This does not seem to be working with API version 16.  I will note that I'm trying to do this via an Apex Controller for a Visualforce page, not that it "should" matter.

 

Debug log seems to indicate that the assignment rule piece is being skipped.  Actual behavior is thatthe case is left as assigned to the person that created it (not the default user for when assignment rule fails).  I am also NOT using the standardController for Case, but rather a custom one.  I don't think this should matter either (since I can still save this code to the server without error...), but adding on just in case.

 

Please advise.

 

 

 

Message Edited by paul-lmi on 06-19-2009 07:55 PM
paul-lmipaul-lmi

i see that this was a bug in the Spring '09 release this thread

 

thread link

 

did this bug get reintroduced with the Summer '09 release?

paul-lmipaul-lmi
i ended up opening a case for this.  it's definintely looking like a bug, and there's no workaround.
paul-lmipaul-lmi

support's response:

 

Just following up. It turns out this issue is related to a bug we are aware of. We are currently working on the fix for this issue. We apologize for any inconvenience this may have caused.

I will close this case and reference the bug.

Please reference this case if you have any questions regarding this bug in the future as bug numbers are internal.

 

 

they could not provide any ETA on resolution.

crmguy.ax226crmguy.ax226

This worked just fine for me executing the following code as anonymous block:

 

//set the assignment rules to actively route case Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; //fieldsDisabled = true; Case cse = new Case( subject = 'Testing Assignment' , description = 'Testing Assignment' , origin = 'Email' , status = 'New' , type = 'Technical Issue' ); cse.setOptions(dmo); insert cse;

 

and also the following VisualForce controller constructor:

 

 

public Case cs {get; private set;} public CustomerCaseExtension(ApexPages.StandardController stdController) { this.cs = (Case)stdController.getRecord(); Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; cs.setOptions(dmo); }

 

 

I'm sure that you've confirmed that your assignment rules work as expected when using the native interface and "Assign using active assignment rules" option.

 

Best of luck.

 

Regards,

Cliff

paul-lmipaul-lmi

i haven't tried anonymous execution.  this isn't for a controller extension it's completely custom, and even so, you shouldn't have to set these options in both the extension code and the code preceding the insert.

 

either way, it's a confirmed bug in the way that I implemented it, which is completely compliant for how it "should" work.

paul-lmipaul-lmi

now this is interesting.  if i don't use a list of cases, but rather a single case

 

Case cs = new Case();

 

instead of

 

Case[] cs = new Case[0];

 

it seems to work fine.

paul-lmipaul-lmi
and now it stopped working again, no changes after the "working" code was deployed.  WTF.
paul-lmipaul-lmi
could someone from Salesforce please indicate _when_ this bug is going to be fixed.  Support told me "before the next release", but that's not finite enough of a timeline.  Is this going to be resolved in the next couple weeks, or not?
paul-lmipaul-lmi

hack workaround, based on the comments in this post

 

i'm not keen on inserting a case and then having to immediately update it though.  i have a feeling that this is how SF does it with the built in logic though, since i've run into logic/order issues when using afterInsert triggers (stuff was firing twice).

 

 

public PageReference createCase(){ //set the assignment rules to actively route case Database.DMLOptions dmo = new Database.DMLOptions(); //dmo.assignmentRuleHeader.assignmentRuleId = '01Q7000000034jD'; dmo.assignmentRuleHeader.useDefaultRule = true; dmo.EmailHeader.triggerUserEmail = false; system.debug('DMLOptions set to ' + dmo); //fieldsDisabled = true; Case cse = new Case( subject = subject, description = description, suppliedemail = email, contactemail__c = contactEmail, suppliedname = suppliedname, suppliedphone = suppliedPhone, product__c = productstring, operating_system__c = operatingsystemstring, type = typestring, lang__c = lang, origin = 'Email' ); system.debug('case info before insert' + cse); insert cse; cse.setOptions(dmo); update cse; //get the case number casenumber = [select id, casenumber from case where id = :cse.id].casenumber; fieldsDisabled = True; showSubmitLink = False; showThanks = True; showForm = False; system.debug('showthanks = ' + showThanks); system.debug('error: ' + ex); ApexPages.addMessages(ex); } return null; }