0

I want run a rule from trigger (Lead Assignment rule - default) when a new lead is created. I tried something but its not working. Don't know which one is correct way to do that. below you can find my code with bugs. I got something from this link but I don't want to do database operations. I just want to run my rule. Someone please help me.

trigger leadAssignment on Lead (after insert) {
    for (Lead l : Trigger.new) {
        if(l.My_Field__c != null && !l.My_Field__c.isEmpty())
        {
           Database.DMLOptions dmo = new Database.DMLOptions();
           dmo.assignmentRuleHeader.useDefaultRule = true;   
        }
    }
}

isEmpty() not working any better way to do that? If this information is not enough just comment it I will update. Thanks in advance.

2
  • "...but I don't want to do database operations". Why??? – Chris Duncombe Jul 14 '15 at 15:21
  • Did you read @crop1645 answer to the post you referred to? You must call an @future method for the lead reassignment via a DML operation. Also, if you're inserting new records, you can specify the lead assignment rule in dataloader. Also, the code you're using includes DML. Any change to the database is a DML operation. – crmprogdev Jul 14 '15 at 15:26