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
kamal3883kamal3883 

Assignment rules not firing when enforced through after update trigger

Hi All,

I am trying to enforce assignment rules through after update trigger. Here is complete scenario:

1) Time based workflow is updating owner of case.
2) In after update trigger, i am enforcing assignment rules.

Checked debug logs and figured out after update part is running successfully. There is no exception but assignment rules are not working. 

If i am updating case owner directly, assignment rules are working correctly.
Raj VakatiRaj Vakati
Can you try to set the below code to trigger assignment rule 

 
Database.DMLOptions options = new Database.DMLOptions();

options.assignmentRuleHeader.useDefaultRule = useDefaultRule;

 
Raj VakatiRaj Vakati
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.assignmentRuleId= '01QD0000000EqAn';

Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);
insert l;

 
kamal3883kamal3883
Thanks Raj for your reply. I am using dmloptions in my code. Here is code written for this:
Database.DMLOptions dmlOpts = new Database.DMLOptions();
                dmlOpts.assignmentRuleHeader.useDefaultRule= true;
                system.debug('testassignment****' + skipAssignmentRules);
                for(sObject sObj: [Select id,owner.Name,ownerId,status from case where Id In : newCaseList]){
                    case cs = (Case)sObj;
                    system.debug('testassignment****' + cs.owner.Name);
                    case csOld = (Case)oldCaseMap.get(cs.Id);
                    if(cs.OwnerId != csOld.OwnerId){ 
                        cs.setOptions(dmlOpts);
                       
                        system.debug('testassignment****');
                        filteredCaseLst.add(cs);
                    }   
                }
                if(filteredCaseLst.size() > 0){
                    skipAssignmentRules = true;
                    database.update(filteredCaseLst,dmlOpts);
                }