You need to sign in to do that
Don't have an account?
Ricki Reay
Prevent Trigger On Specific Case Record Type?
I am trying to create a trigger that automatically fires my org's case automation rules (i.e. auto assigns it to the Case Queue so that we can use the quick actions which do not have the "Use Active Assignment Rules" feature yet to create cases). However, there is one case type that does not go to a Case Queue and therefore, I do not want to it automatically use active assignment rules as it will automatically assign it to our Default Case Owner.
My current trigger is:
How do I go about doing so?
Thanks in advance for any and all help. It is GREATLY appreciated.
My current trigger is:
trigger AssignmentRulesonCaseTrigger on Case (after insert) { List<Id> caseIds = new List<Id>{}; if(trigger.IsAfter && trigger.isInsert ){ for (Case theCase:trigger.new) caseIds.add(theCase.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); } }I want to make a condition saying that the trigger does not fire if the case record type is = "Member Concern" or the specific Record Type ID associated to this record type.
How do I go about doing so?
Thanks in advance for any and all help. It is GREATLY appreciated.
Please try the below changes in your trigger:
trigger AssignmentRulesonCaseTrigger on Case (after insert) {
List<Id> caseIds = new List<Id>{};
Id RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Member Concern').getRecordTypeId();
if(trigger.IsAfter && trigger.isInsert ){
for (Case theCase:trigger.new)
{
if(theCase.RecordTypeId != RecordTypeId)
{
caseIds.add(theCase.Id);
}
}
List<Case> cases = new List<Case>{};
if(caseIds.size() > 0)
{
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);
}
}
}
Thanks,
Maharajan.C
All Answers
Please try the below changes in your trigger:
trigger AssignmentRulesonCaseTrigger on Case (after insert) {
List<Id> caseIds = new List<Id>{};
Id RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Member Concern').getRecordTypeId();
if(trigger.IsAfter && trigger.isInsert ){
for (Case theCase:trigger.new)
{
if(theCase.RecordTypeId != RecordTypeId)
{
caseIds.add(theCase.Id);
}
}
List<Case> cases = new List<Case>{};
if(caseIds.size() > 0)
{
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);
}
}
}
Thanks,
Maharajan.C
Thank you so much for such a prompt reply. I just tweaked the third line so that it is referencing the case object (as it is the Member Concern case-type that I am restricting the trigger from acting on) and it appears to be working perfectly!