Case Assignment Rule will not be triggered if the case got created from Apex..how to deal with that?

Case assignment rules allow you to automatically route Cases to the appropriate users or queues. A Case assignment rule consists of multiple rule entries that define the conditions and order for assigning cases. You can create multiple rules (for example, a Standard rule and a Holiday rule), but only one rule can be "active" at a time.

From a standard UI, a user can trigger assignment rules by simply checking the "Assign using active assignment rules" checkbox under the Optional section. The problem arises when your app needs to insert the Case from Apex and wants to trigger assignment rules. Using this script, a Case will be inserted but assignment rules will not be triggered as there is no such field "Assign using active assignment rules" on Case.

We can solve that by creating Database.DML operation to fire the assignment rule, the following script will show to perform that:

//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 ;

Now when the Case is inserted using this script, the case assignment rule gets triggered!


Gowtham Tadavarthi

Salesforce/Omnistudio Developer at Virtusa || 8X Salesforce || 3X Vlocity Certified || 1X Accredited Professional || Trailhead Ranger

1 年

While creating case record from flow how can we trigger assignment rules?

回复
Ahmed Keshk

Salesforce CTA | Sr. Program Architect at Salesforce

4 年

The same applies for creating cases from REST API. You need to set the Assignment Rule Header. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm

要查看或添加评论,请登录

社区洞察

其他会员也浏览了