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
simwr77simwr77 

Using DMLOptions in Trigger with WF not working

Hello,
I need to enforce the Case assignment rules by code because I seen that removing the flag "Assign using active assignment rules" from the layout the flag assignment rules are not executed despite the default value is selected by default.

 

I'm trying to enforce the rules using a trigger and the following code seems to work partially

 

trigger Case_SetHandlerAssignmentRule on Case (after insert, after update) {
	List<Id> caseIds = new List<Id>{};
	for(Integer i = 0; i<Trigger.new.size(); i++){
		caseIds.add(Trigger.new[i].Id);
	} 
	List<Case> cases = new List<Case>{}; 
	for(Case c : [Select Id from Case where Id in :caseIds]){
		Database.DMLOptions dmo = new Database.DMLOptions();
		dmo.assignmentRuleHeader.useDefaultRule = true;
		c.setOptions(dmo);
		cases.add(c); 
	}
	Database.upsert(cases);
}

 

For example my assignment rule is triggered when Case Origin is equal to "Web" but when Origin is set by a Workflow the assignment rules don't work.

 

Looking through the documentation(http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm)

I found this note 

"During a recursive save, Salesforce Skips steps 7 through 14." where 7 is "Executes assignment rules"


This is the problem?

Any Idea/Solutions?

 

Thanks

Simone

Damien_Damien_

For example my assignment rule is triggered when Case Origin is equal to "Web" but when Origin is set by a Workflow the assignment rules don't work.

There is a checkbox on the workflow, that says something like 'recalculate something rules'.  I don't remember the exact wording, but if you have that box checked, it may fire the triggers again.  (Workflows happen AFTER triggers fire.  That is why it is currently not working how you expect.)

simwr77simwr77

I know,

the name is "Re-evaluate Workflow Rules after Field Change" on the filed update and it was released with Spring 12 but is use only for retrigger Workflow Rules.

 

I did a  test but assignment rules and validation rules are not retriggered.

Damien_Damien_

Sorry then, that was the only idea that I could come up with.