Dec 8, 2011

Case Assignment Rules From Apex - Database.DMLOptions

This is really very important for users who use native cases with assignment rules.

I have assignment rule defined on Case which says if the "Status" of case is "New" then assign that case to "System Admin" (User in my organization)

Now when I insert a case manually with "Assignment using active assignment rules" checkbox checked then assignment rule works fine, and "System Admin" is assigned as the Case Owner.

Now I want to create the case from my apex code and also want assignment rules to be triggered. But the problem is we are not able to access the "Assignment using active assignment rules" checkbox in apex. Now am stuck because there is a lot of code already written for case insertion, so what is the solution for this?

This code :
Case newCase = new Case(Status = 'New') ;
insert newCase ;

inserts the case but assignment rules are not triggered so case owner in my scenario remains "Ankit Arora" and expected was "System Admin"

Solution is using Database.DMLOptions. Now before inserting the case I use Database.DMLOptions and with my case insertion assignment rules are also triggered, this is all what I want.

When I use this code :
//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();

Case newCase = new Case(Status = 'New') ;
insert newCase ;

It inserts the case and my assignment rule which is in active state get fired and Case Owner becomes "System Admin"


  1. This comment has been removed by the author.

  2. It's more reliable to use the default option:

    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule= true;


  3. Do you have a test class for this?

  4. Nice Blog! Experience the Best Assignment Writing Services at Assignment Help Sydney Australia

  5. Online assignment help by My Assignment Services has been trusted by millions of students worldwide for over a decade. We have been providing complete academic assistance to students struggling with their college and university tasks. Whether it is an essay, dissertation, case study or any other form of assessment, you can trust us for 100% original, well-researched and referenced academic documents that ensure High-Distinction grades. A Essay Writing Help, academic services provider such as My Assignment Services, is well-known for its 24-hour online assistance on the WhatsApp platform. Students can reach out to us with their queries at any point of the day or night and get the most effective solutions for them. Our best online academic help experts talk about how to select and evaluate the right academic sources, You can Buy Assignment which will help you clear all your assignment-related doubts at low cost.

  6. My Assignment Services constantly aim to expand our base of assignment help and call in international experts who are ex-professors from reputed business schools, management schools, engineering universities from across the globe. this provides you with an opportunity to get a global and world perspective in your answers and lets you connect with a writer who understands you. My Assignment Services do not make empty promises and have always achieved what we promised our clients by online Do my assignment. If you need any academic consultation for any assignment type, our team of online assignment helper is available ready to cater to your needs any given moment. We are working round the clock and 365 days of the year. My Assignment Services is your first and last destination for every query you have related to ‘help my assignment’ because we guarantee you the lowest possible price of assignment help sydney with the unmatched quality of assignments in Australia.

  7. Did anyone get a test class for the above code?