+ Start a Discussion
Shiva ShankarShiva Shankar 

Hi I am getting the error on Account Record Page while editing Account record from UI Error: First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.AccConTestTrigger

Hi I am getting the error on Account Record Page while editing Account record from UI  Error: First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Trigger.AccConTestTrigger and trigger code is as below

trigger AccConTestTrigger on Account (After update) {
  
    if(trigger.isAfter && trigger.isUpdate){
        System.debug('this is in isAfter and isUpdate context');
     List<Contact> conList=new List<Contact>();
     for(Account acc : trigger.new ){
         Contact con=new Contact();
         con.AccountId = acc.Id;
         System.debug('Account Id value is --->'+con.AccountId);
         System.debug('Account Id value from the screen --->'+acc.Id);
         con.Department = 'The Last Dep';
        conList.add(con);
     }
    update conList;
  }
}
Could some one please help me in this,how to solve this
Andrew GAndrew G
You are invoking a update on the contact list conList , yet this list would contain new contact records that have no Id  .  To invoke an update you will need an Id because how else will the Update call know which records to update.

In this case, for your code change your  update conList;    to   insert conList;

regards
Andrew
Shiva ShankarShiva Shankar
User-added image
Hi Andrew, I have changed to insert DML operation still i am getting error.Please see the attachment.
Andrew GAndrew G
Contact requires a last name to be saved.
 
Contact con=new Contact();
         con.AccountId = acc.Id;
         con.LastName = acc.Name ;
         System.debug('Account Id value is --->'+con.AccountId);
         System.debug('Account Id value from the screen --->'+acc.Id);
         con.Department = 'The Last Dep';
        conList.add(con);

note that because you are using after update trigger context, this trigger will create a new contact every time the account record is updated.

regards
andrew
mukesh guptamukesh gupta
Hi Shiva,

On After update trigger, contact insret into account then Account will update and again trigger execute it's a recusrrion 

so you need to use below code
 
trigger AccConTestTrigger on Account (After insert) {
  
    if(trigger.isAfter && trigger.isInsert){
        System.debug('this is in isAfter and isUpdate context');
     List<Contact> conList=new List<Contact>();
     for(Account acc : trigger.new ){
         Contact con=new Contact();
         con.AccountId = acc.Id;
         System.debug('Account Id value is --->'+con.AccountId);
         System.debug('Account Id value from the screen --->'+acc.Id);
         con.Department = 'The Last Dep';
        conList.add(con);
     }
    Insert conList;
  }
}
If this solution is usefull for you, Please mark as a Best Answer to help others.


Regards
Mukesh



 
 
Andrew GAndrew G
@mukesh
The Trigger is on Account.  The record being inserted is a Contact.  The insertion of a Contact will not update the Account record unless there is some trigger or other automation on the Contact to update the Account. 

Based on the code supplied, there is no indication of recursion.

Regards
Andrew