I have an apex class assigning a rule to all cases

    global class AP04_CaseCallAssignmentRule {

/* this method is invoked from process builder for reassigning case   */     
  @InvocableMethod(label='Case Call Assignment Rule' description='call reassignment rule')
  public static void CaseCallAssignmentRule (list<id> CaseIds) { 
  system.debug('### AP04_CaseCallAssignmentRule cases: ' + CaseIds);

    // Fetching the assignment rules on case
    AssignmentRule AR = new AssignmentRule();
    AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
    //Creating the DMLOptions For "Assign using active assignment rules" checkbox
    Database.DMLOptions dmlOpts = new Database.DMLOptions();
    dmlOpts.assignmentRuleHeader.assignmentRuleId = AR.id;

    list <case> cases = new list <case>();
    for (Case c :[select id from case where id in :caseIds]){
    } // for Case to reassign
    if (cases.size() > 0){
     } //

  system.debug('### AP04_CaseCallAssignmentRule cases after update: ' + cases);
  } // invoke 
} // class

But I am trying to bypass the Case Assignement for a Trigger, so the Case Owner is not reassigned to a queue after the TaskTrigger.apxt executes. I have tried to add the following to my code. But when adding it to my class, my trigger stop working altogether.

Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.AssignmentRuleHeader.useDefaultRule = false;
                c.OwnerId = c.LastModifiedById;

How can I make sure that my TaskTrigger bypass the Case Assignment Rule, so the case owner is not automatically updated? Thanks

Here is my Class Handler for the trigger:

public class TaskTriggerHandler {

public static void createAircallTask(List<Task> taskList) {
    Set<Id> relatedCaseIds = new Set<Id>();
    for(Task t :taskList) relatedCaseIds.add(t.WhatId);
    List<Case> caseList = new List<Case>();
    Map<Id, Case> caseWithAircallTaskMap = new Map<Id, Case>([SELECT Id, First_Voice_Interaction__c FROM Case WHERE Id IN:relatedCaseIds]);
    for(Task t : taskList) {
        if(t.whatId != null &&  t.callDisposition!= null && t.callDisposition.containsIgnoreCase('aircall')) {
            System.debug('#### Aircall debug ' + t.whatId != null && t.callDisposition.containsIgnoreCase('aircall'));
            //Case c = New Case();
            if(caseWithAircallTaskMap != null && caseWithAircallTaskMap.containsKey(t.whatId)) {
                Case c = caseWithAircallTaskMap.get(t.whatId);
                System.debug('Case Id ' +c);
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.AssignmentRuleHeader.useDefaultRule = false;
                c.OwnerId = c.LastModifiedById;
                System.debug('###setOptions ' +c);
                if(c.First_Voice_Interaction__c == null) {
                    c.First_Voice_Interaction__c = t.createdDate;
                    if(t.WhatId == c.Id) {
                        System.debug('###caseList ' +caseList);
    if(caseList.size() > 0) {
        update caseList;


Here the TaskTrigger.apxt

trigger TaskTrigger on Task (after insert, after update) {

if(Trigger.isAfter && Trigger.isInsert || Trigger.isUpdate)



1 Answer 1


It doesn't matter what assignmentRuleHeader you use in your Task trigger, as the case trigger is a sub-transaction of the task trigger, so it will always win in the end. What you need is some coordination between the two pieces of code. A static variable can help here:

public class AP04_CaseCallAssignmentRule {
  public static Boolean skipAutoAssign = false;
  public static void CaseCallAssignmentRule (list<id> CaseIds) { 
  if(skipAutoAssign) {
  // Rest of code ...

Then, in your task trigger handler class:

 AP04_CaseCallAssignmentRule.skipAutoAssign = true;
 update caseList;
 AP04_CaseCallAssignmentRule.skipAutoAssign = false;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .