I need help with writing an Apex Trigger Code to get Lead Assignment Rules to apply to leads imported via apex code. The imported code was created by a consultant. I looked for some guidance online and I came up with the following code

trigger LeadAssign on Lead (after update) 
 List<Id> lIds=new List<id>();
For (lead l:trigger.new){
    if (l.IsConverted==False){
        lIds.add(l.Id);   }
if (AssignLeads.assignAlreadyCalled()==FALSE){
    system.debug('Assign already called? '+AssignLeads.assignAlreadyCalled());
public global class AssignLeads{

public static Boolean assignAlreadyCalled=FALSE;

public static boolean assignAlreadyCalled(){
return assignAlreadyCalled;

public static void assign(List<Id> lIds){
List<Lead> leads=[SELECT Id FROM Lead WHERE Id IN: lIds];
For (lead l:leads){
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;



Thank you for any help

  • 1
    Can you elaborate on this, what you want to do is not quite clear. What have you done already? What is this code not doing? Anything else that you can tell us that would help in assessing what is wrong? Jan 27, 2016 at 20:05
  • are you trying to (re)run the assignment rules every time an unconverted Lead is updated?
    – cropredy
    Jan 27, 2016 at 22:07
  • Thank you for your help. When the leads came in with the API the rules were not triggering. I recreated the Lead Assignment rules in the Process Builder and it worked. Thank you Feb 2, 2016 at 19:36

1 Answer 1


I found a simple solution to fix the issue of the Lead Assignment rules not being run when the leads were submitted via the API. I recreated the Lead Assignment rules in Process Builder. Thank you everyone for your help

You must log in to answer this question.

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