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
ColaCola 

MISSING_ARGUMENT, Id not specified in an update call

Hi, 

I'm trying to create a trigger that checks a lead's email domain when it is created. If this email domain matches an exisiting account domain, then the lead owner gets set to that corresponding account owner. However, I am getting the following error: 

Apex trigger AssignNewLeadToAccount caused an unexpected exception, contact your administrator: AssignNewLeadToAccount: execution of BeforeInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.AssignNewLeadToAccount: line 21, column 1

Here is the trigger code: 

trigger AssignNewLeadToAccount on Lead (before insert)  {

	public list<Lead> LeadsToUpdate = new List<Lead>();

	Map<string,Id> DomainAccountMap = new Map<string,Id>();
    
    for (Account a :[SELECT ownerID, Email_domain__c FROM Account WHERE Email_domain__c != null]) {
		DomainAccountMap.put(a.email_domain__c, a.ownerId);
    }

    for(Lead l : Trigger.new) {
        ID owner = DomainAccountMap.get(l.Email_domain__c);
        if(owner != null) { 
            Lead lead = new Lead(Id=l.Id, OwnerID = owner); 
            LeadsToUpdate.add(lead);
            l.Skip_Lead_Assignment__c = true; 
        }  
    }
    
    if(LeadsToUpdate.size() > 0){
        update LeadsToUpdate;
    }
}
Any help is appreciated. Cheers
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
You will not get id for update in before insert trigger.
Please use Upsert and check if it works.