[SalesForce] Run case assignment rules after approvals

I am building a complex case management platform for an airline client for whom all cases must be approved BEFORE they are assigned to queues.

We note that because of sequencing within SFDC that the field update in the final approval actions (approval status=Approved) is not detected and needs a further EDIT & SAVE to happen on the case to cause the assignment rules to fire and correctly assign the case to the required queue.

In summary – ideas sought on how to get the assignment rules to fire at the end of or as consequence of an approval process field update (will consider apex if needed).

Best Answer

Create a checkbox field like isApproved and during final approval action update this field from workflow field update.

Since you are using Assign using active assignment rules checkbox to fire assignment, which cannot be automatically possible after workflow field update as you are not in UI.

So, you need to write an after update trigger to fire assignment rule:

trigger CaseAssignment on Case (after update) {
    List<Case> caseList = new List<Case>();

    if(Trigger.isAfter && Trigger.isUpdate){
        for (Case caseObj : Trigger.new)
        {
            Case oldCase = Trigger.oldMap.get(caseObj.id);
            if (!oldCase.isApproved__c && caseObj.isApproved__c) {
                caseList.add(new Case(id = caseObj.id));
            }
        }
    }
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;
    Database.update(caseList, dmo);
}

Refer Triggers and Order of Execution

If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.


Approval Process setup:

If Type is Electronic it will be submitted for approval and after getting approved, isApproved field will be updated to true.

approval

Case assignment rule:

assignment rule

Case record during submission for approval

during submission

Case is assigned to queue after getting approved, by virtue of after trigger to fire assignment rule.

case after approval