I am trying to invoke Lead assignment rule when ever certain criteria meets the trigger should fire.

But I am getting the following error :

execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []:

Can anyone guide me where I am donig wrong.Thanks in advance. My Trigger:

trigger LeadAssignment on Lead (After insert,After update) {

    List<Lead> updateLeads = new List<Lead>();

    Lead newLead = new Lead();
    for(Lead l : trigger.new)
        if(l.Status == '01-New' || l.Status == '50-Qualified')
            AssignmentRule AR = new AssignmentRule();
            AR = [select id from AssignmentRule where SobjectType = 'Lead' and Active = true limit 1];

            Database.DMLOptions dmlOpts = new Database.DMLOptions();
            dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;

           // updateLeads.add(newLead);


    update newLead;


You are trying to update Lead newLead = new Lead(), you didn't give it an ID so it doesn't know who it needs to update. You would have to do something like newLead = new Lead(Id=l.id) inside the loop;

But in general, i think you need to bulkify your code. Currently you will only do the update on one lead, and it will be the last lead in the trigger.

| improve this answer | |
  • Hi Dana Griff, Can you please guide me with code. I have tried newLead = new Lead(Id=l.id) inside the loop;but it is not working. – siri Sep 4 '19 at 11:04
  • Please update the question so i can see what you did – Dana Griff Sep 5 '19 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.