How to assign Assignment Rule to Case record using Apex in Salesforce?

How to assign Assignment Rule to Case record using Apex in Salesforce?

assignmentRuleHeader.useDefaultRule in Database.DMLOptions can be used to assign or invoke or trigger Assignment Rule to Case record using Apex in Salesforce.

Sample Code:

Case objCase = new Case(
    Subject = 'Testing DML Options for Assignment Rule',
    Status = 'New',
    Description = 'Testing',
    Origin = 'Web',
    Priority = 'Low'
);
Database.DMLOptions objDMLOption = new Database.DMLOptions();
objDMLOption.assignmentRuleHeader.useDefaultRule = true;
objCase.setOptions( objDMLOption );
insert objCase;

this is applicable even when you update the case.

Output:

Leave a Reply