function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
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();

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