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
User Migration 6User Migration 6 

Trigger to run Case Assignment Rule when User edit with Inline editing

Hello,

do you have any trigger to force Case Assignment Rule to run when a User edit with inline editing?
I know that there are some ideas to correct this and the only workaround is to use a trigger.

I'm using this code but is not triggering any Rule:
 
trigger CaseAssignmentTrigger on Case (before update) {
  
  for (Case theCase:trigger.new) {
      Database.DMLOptions dmo = new Database.DMLOptions();
      dmo.assignmentRuleHeader.useDefaultRule = true;
      theCase.setOptions(dmo);
      
      System.debug ('working');
  }
    
        
}



Thank you.
Best Answer chosen by User Migration 6
Shivdeep KumarShivdeep Kumar
Hi,
try this it ll work for you sure..
trigger myTrigger on Case (after insert, after update) {
  
Set<Id> caseIds = new Set<Id>();

        for (Case cs :trigger.new) {
            caseIds.add(cs.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);
}

you can also check this link for detail info..
http://developer.force.com/cookbook/recipe/running-case-assignment-rules-from-apex

Thanks
Shivdeep

All Answers

Shivdeep KumarShivdeep Kumar
Hi,
Please take a look on below link, it will help you.
https://help.salesforce.com/articleView?id=000187821&type=1

Please let me know if this help.

Thanks 
Shivdeep
 
User Migration 6User Migration 6
Thank you,

I actually don't know how to modify my trigger in order to make it work as specified in that article.
Shivdeep KumarShivdeep Kumar
Hi,
try this it ll work for you sure..
trigger myTrigger on Case (after insert, after update) {
  
Set<Id> caseIds = new Set<Id>();

        for (Case cs :trigger.new) {
            caseIds.add(cs.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);
}

you can also check this link for detail info..
http://developer.force.com/cookbook/recipe/running-case-assignment-rules-from-apex

Thanks
Shivdeep
This was selected as the best answer