function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
csfdccsfdc 

How to bulkify Apex for LeadAssignmentRules

I'm following the work of automationchampion (https://automationchampion.com/tag/run-lead-assignment-rules-for-process-builder/)on using process builder and an Apex class to invoke Salesforce routing rules once a lead meets certain critera. Everything is working fine except when I import mulitple records with the Dataloader, in which case the process fails because my code is not bulkified. Has anyone bulkified this before?

Here is my Apex class.

public class AssignLeadsUsingAssignmentRules {     @InvocableMethod     public static void LeadAssign(List<Id> LeadIds)     {             Database.DMLOptions dmo = new Database.DMLOptions();             dmo.assignmentRuleHeader.useDefaultRule= true;                       Lead Leads=[select id from lead where lead.id in :LeadIds];             Leads.setOptions(dmo);          
            update Leads;   
      }
}