0

We have a case assignment rule that will get fired when a case is inserted normally from the UI. We also have a global action that will create a case, in this scenario I am aware the case assignment rules will not be fired when a case is inserted using global actions.

For this the work around is to have a process builder, but our concern is we don't want to maintain case assignment logic at two places.

My idea is to maintain case assignment logic at Assignment rules and to invoke assignment rules using PB. Is it possible?

Please advice

2 Answers 2

3

You can use process builder to invoke assignment rules, but you will have to write an invocable apex method and then call this method via a scheduled action in the process builder (preferably with few seconds or few minutes of delay). Using Scheduled action is a key point here and note that using Immediate action to call the apex method will not help.

Refer to my answer here to understand the reason behind why using scheduled action is important in your case and how order of execution impacts the assignment rules execution.

Sample code inside the invocable apex method should be something like the snippet shown below:

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
// Query case record here or if the record was passed as input var, then use it here.
// Replace <Case SObject> with the record variable
<Case SObject>.setOptions(dmo);
update <Case SObject>; // or Database.update(<Case SObject>, dmo);

Official documentation on DMLOptions and sample code can be found here.

Official documentation on Invocable apex method and sample code can be found here.

1
  • 1
    Alternative that I use: PB calls invocable apex which delegates to an async (future/queueable) the execution of the DML w/ assignmentRulesHeader set.
    – cropredy
    Commented Nov 6, 2020 at 20:01
0

There is no configurable ways to run assignment rules from PB. Better create a class with InvocableMethod and run the rules in the method.

Sample code looks like this:

public class CaseAssignmentHelper {
    @InvocableMethod
    public static void assignCases(List<Id> caseIds){
    
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            List<Case> lstCase=[SELECT Id from Case where Id in :caseIds];
            for (Case obj:lstCase){
                obj.setOptions(dmo);
            } 
            update lstCase;
   }
}
1
  • setOptions is a method available on SObject class. So, it cannot be directly used on the collection lstCase. The code snippet requires a minor tweak.
    – arut
    Commented Nov 6, 2020 at 6:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .