Running Case Assignment Rules From Salesforce Apex

Running Case Assignment Rules From Salesforce Apex

Hi All,

We all know that Case Assignment Rule decides how cases are assigned to users or put into queues. We can create multiple assignment rules, but only one rule can be “active” at a time.

We can trigger assignment rules by simply checking the “Assign using active assignment rules” checkbox under the Optional section of the Case creation page from Standard UI. Or We can set it default true under the “Layout Properties“of the case page layout.

case assignment

But do you know!!! When we are inserting the Case via Apex, the assignment rule will not be triggered  as there is no such field “Assign using active assignment rules” to be checked in the Apex.

DON’T WORRY. Here in this blog you will know how to run assignment rule through apex.

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

The above piece of code is fetching the active assignment rule of Case and then creating the DMLOptions for the “Assign using active assignment rules” checkbox. Actually Database.DMLOptions class provides advanced information.

So now when the Case is inserted through Apex with the Database.DMLOptions, the assignment rule gets invoked easily.

Happy Salesforce!

0 Comments

Leave a Reply

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?