0

I have a case assignment rule which works well when creating new cases from the cases list view.

But I have a Global action, "new case" when I try creating case from here, assignment rule is not fired. Please help.

I dont know to write triggers but still after doing some research I wrote this which gives errors, Please tell me a simple solution

trigger callAssignmnetRule on Case (before insert) {
//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;
Case newCase = new Case(Status = 'New') ;
//Setting the DMLOption on Case instance
newCase.setOptions(dmlOpts);
insert newCase ;
}```
1

1 Answer 1

0

This seems to be some known issue from salesforce side. You can upvote for the same.

The trigger logic you need to write the trigger on after insert context and the trigger logic should be as something as below.

Set<Id> caseIdSet = new Set<Id>();
for(Case c : trigger.new) {
caseIdSet.add(c.Id);
}
 AssignmentRule AR = new AssignmentRule();
    AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
List<Case> caseList = new List<Case>();

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.AssignmentRuleHeader.assignmentRuleId =AR.id;

for(Case c : [SELECT Id FROM Case WHERE Id IN: caseIdSet]) {
c.setOptions(dmo);
caseList.add(c);
}
update caseList;

The above code is just very basic code . You need to modify the code based on your requirement.

You must log in to answer this question.

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