I have a fairly simple Process Builder where, if leads meet certain conditions, we will re-run the assignment rules. This is done with a scheduled action 0 Hours After LastModifiedDate that calls an invocable method to set the DML Options and update the leads.
This works just fine if only one record is updated to meet the conditions, but fails for multiple records at the same time. I can see that the scheduled actions get created in the Paused and Waiting Interviews list, but nothing actually happens. I don't receive any error emails, but the leads do not get reassigned.
I've looked around SFSE and have seen a couple of similar questions, but nothing that has an answer that addresses my issue. The records still meet the criteria, so they shouldn't be getting cancelled.
Apex:
public class RunLeadAssignmentRules {
@InvocableMethod
public static void assignLeads(List<Id> leadIds)
{
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead leadsToAssign=[select id from lead where lead.id in :leadIds];
leadsToAssign.setOptions(dmo);
update leadsToAssign;
}
}
What is going on here that I'm missing?