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
FinnArildFinnArild 

assignmentRuleHeader on case updates

Hi - for vacation handling I want to re-run default case assignment as described in the new DMLOptions. However, setting this in the after update seems to have no effect:

 

 

Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; for (Case c:trigger.new) { c.setOptions(dmo); }

 

 Does anyone have a working example on using this any other place than on insert triggers - if indeed it is at all possible?

 

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf

That's because DMLOptions only apply when you're actually doing an update, which you're not here (by the time this happens your update's already over).

 

This post is close but probably won't work for you because you can't trigger an update from an update.  Instead, take the update code in that post and put it in an @future method, and call your @future method from your after update.  And probably set some flag that you check in your trigger too so you don't make an infinite loop of @future methods and after updates.

All Answers

werewolfwerewolf

That's because DMLOptions only apply when you're actually doing an update, which you're not here (by the time this happens your update's already over).

 

This post is close but probably won't work for you because you can't trigger an update from an update.  Instead, take the update code in that post and put it in an @future method, and call your @future method from your after update.  And probably set some flag that you check in your trigger too so you don't make an infinite loop of @future methods and after updates.

This was selected as the best answer
FinnArildFinnArild

Ok - so this worked out fine - allthough it is impossible to test properly. I thought I'd paste my asynchronous code here, to help others with similar issues.

 

I added a field on the case to make sure it didn't reassign endlessly

 

@future public static void rerunCaseAssignmentRules(String cId) { Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule = true; Case c = [select Id, Reassigning__c from Case where Id =: cId]; c.setOptions(dmo); c.Reassigning__c = True; Database.update(c); c.Reassigning__c = False; Database.update(c); }