We have a couple of actions on the Opportunity that create Cases. In order to trigger case assignment rules, I have a simple apex class that is being called by process builder. I'm very new to apex, and put together the class based on some suggestions from related Salesforce ideas. It works when I test it out in my personal dev org but not the sandbox or production instances where it is actually needed. I suspect something could be off with my process builder or the class, and just need a second pair of eyes on it. I'd appreciate any input.
Class:
public class CaseAssignment {
@InvocableMethod
public static void CaseAssign(List<Id> CaseIds)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
Case Cases=[select id from case where case.id in :CaseIds];
Cases.setOptions(dmo);
update Cases;
}
}
Test Class (the test passes)
@istest
class CaseAssignment_Test {
@istest
static void testCaseAssignment(){
Case c = New Case ();
c.Client_Access_End_Date__c = Date.today();
insert c;
List<Id> caseids = new List<Id> ();
caseIds.add(c.id);
CaseAssignment.CaseAssign(caseIds);
}
}
- When to start the process: when a record is created or edited
- criteria: I tried setting it to no criteria, or a formula of "true"
- immediate actions: setting a text field to check that the process runs. It does. I see the text field on my test case updated.
- 0 hours after, invoke apex class. No case assignment takes place.
Result: When a case is created via the custom action, I can see the text field update via process builder. I see the apex step under "paused and waiting interviews" via Setup > flows. I get no error message, but the case does not change ownership.
Other observations: - when a case record is created via the case layout and the "assign using active assignment rules" field is checked, the case gets re-assigned properly. - The same case class and process builder criteria is selected in my dev org, and I see the case get re-assigned as expected.