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]){
c.setOptions(dmlOpts);
cases.add(c);
} // for Case to reassign
if (cases.size() > 0){
update(cases);
} //
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;
c.setOptions(dmo);
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;
c.setOptions(dmo);
System.debug('###setOptions ' +c);
*/
if(c.First_Voice_Interaction__c == null) {
c.First_Voice_Interaction__c = t.createdDate;
if(t.WhatId == c.Id) {
caseList.add(c);
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)
TaskTriggerHandler.createAircallTask(Trigger.New);
}