Assignment and Auto-Response Rules to Case record using Apex in Salesforce

Assignment and Auto-Response Rules to Case record using Apex in Salesforce

To assign or invoke or trigger Assignment and Auto-Response Rules to Case record using Apex in Salesforce, assignmentRuleHeader.useDefaultRule and emailHeader.triggerAutoResponseEmail in Database.DMLOptions should be set to true.

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

Similarly, we have to use emailHeader.triggerAutoResponseEmail in Database.DMLOptions can be used to assign or invoke or trigger Auto-Response Rule to Case record using Apex in Salesforce.

Sample Code:

Case objCase = new Case(
    Subject = 'Testing DML Options for Assignment & Auto Response Rules',
    Status = 'Escalated',
    Description = 'Testing',
    Origin = 'Web',
    Priority = 'Low',
    ContactEmail = '003Ho00001wgsBrIAI'
);
Database.DMLOptions objDMLOption = new Database.DMLOptions();
objDMLOption.assignmentRuleHeader.useDefaultRule = true;
objDMLOption.emailHeader.triggerAutoResponseEmail = true;
objCase.setOptions( objDMLOption );
insert objCase;

Leave a Reply