+ Start a Discussion
Rohit SharmaGRohit SharmaG 

Enable Assign using active assignment rules via Backend

Hi Dears,

I want to enable Assign using active assignment rules via backend , not from pagelayout. please assist on this.

User-added image
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Yes, you can use Database.DMLOptions like below (Soure: ApexCookbook from Ankit Arora): Please mark it as best answer if it works for you. It helps others.

AssignmentRule rules = new AssignmentRule();
rules = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];

//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions Opts = new Database.DMLOptions();
Opts.assignmentRuleHeader.assignmentRuleId= rules.id;

Case newCase = new Case(Status = 'New') ;
//Setting the DMLOption on Case instance
newCase.setOptions(Opts);
insert newCase