We are having an issue where our lead assignment rules are not being processed. I have verified that the rule is active.
We have data integration services in our org that update our leads via data integration rules. These updates do not trigger the lead assignment rules. The goal is to force them to always run as we have a formula field that is used to determine when the lead assignment rule should and should not run. The formula field is checked as the first step in the assignment rule.
I started by following this article. I have an invocable method:
@InvocableMethod(label='forceAssignmentRules' description='forces assignment rules to run')
public static void forceAssignmentRules(List<Id> leadsIds) {...}
This method accepts a formula value in the PB of lead.Id
.
I have also tried:
@InvocableMethod(label='forceAssignmentRules' description='forces assignment rules to run')
public static void forceAssignmentRules(List<Lead> leads) {...}
Since PBs are called in the after part of the execution order I am making sure to query for my leads:
List<Lead> leads = [SELECT Id FROM Lead WHERE Id IN :leadsIds];
--- OR ----
leads = [SELECT Id FROM Lead WHERE Id IN :leads];
I am defining my DML options as:
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.UseDefaultRule = true;
---- OR ----
Database.DMLOptions dmo = new Database.DMLOptions();
Database.DMLOptions.AssignmentRuleHeader asr = new Database.DMLOptions.AssignmentRuleHeader();
asr.UseDefaultRule = true;
dmo.assignmentRuleHeader = asr;
And assigning this dmo to my records by:
database.update(leads, dmo);
---- OR ----
for (Lead l : leads) {
l.setOptions(dmo);
}
update leads;
I have added debug lines into my code so I know that my code is running and there are no errors occurring during execution. With a test lead, if I click edit and go to the bottom and select the option to use assignment rules, the owner is changed as expected. Change the owner back and using the same lead with the above code, the owner does not change.
Future methods are not an option as one of the data services processes via scheduled batchables and future methods cannot be called form batchables.
I have tried a queueable but that created an infinite loop. The queueable updated the leads and then re-enqueued itself. I am currently looking at possibly fixing this infinite loop but it would be nice to not have to use queueables. I suppose even if I did get the above issue fixed, an infinite loop is still very possible.
I am unsure of what I am doing wrong, any help would be appreciated.
WF_RULE_EVAL_BEGIN Assignment
but when looking at the formulas that are being evaluated within that WF they are not in the assignment rule, not sure where they are AND that appears before the code above executes so I'm mostly positive that there are no assignment rules running.