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
Siddharth LakhotiaSiddharth Lakhotia 

How to solve error "DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call"

Hi,

I am facing the error mentioned in subject line , when trying to create a test class for a trigger. can somenone tell me , how do I solve this error

@isTest(SeeAllData = false)
public class OwnerIdchangeTest {
    public static UserInformation__c userInfo;   
    
    static testmethod void OwnerIdChange()
    {
        userInfo = UserInformation__c.getOrgDefaults();
        Profile p = [SELECT Id FROM Profile WHERE Name='Indonesia - Local Admin'];
        User u = new User();
        u.Alias = 'standt';
        u.Email = 'standarduser@testorg.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LastName = 'Testing';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = p.Id;
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.Username = 'standar123456duser@testorg.com';
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
      //  insert u;       
        
        
        u.Business_Unit__c = 'Weber';
        u.Case_Owner__c = True;

        
        UserInformation__c UInfo = new UserInformation__c();
        UInfo.Gypsum_User_Id__c = '0050k000000yLiy';
           UInfo.Weber_User_Id__c = '0050k000000yLiy';
        insert UInfo;
        
        
       List <UserInformation__c> userInfoUpdate = new List<UserInformation__c>([select Id,Weber_User_Id__c,Gypsum_User_Id__c from UserInformation__c where Id =: UInfo.Id]);
        
        Test.startTest();
        for(UserInformation__c UI : userInfoUpdate)
        {
            UI.Weber_User_Id__c = u.Id;
            
            userInfoUpdate.add(UI);
        }
        
            
        
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        //update u;  
        update userInfoUpdate;  
        
        Test.stopTest();       
    }    
    /*static testmethod void ChangeOwnerId()
    {
        userInfo = UserInformation__c.getOrgDefaults();
        Profile p = [SELECT Id FROM Profile WHERE Name='Indonesia - Local Admin'];
        User u = new User();
        u.Alias = 'standt';
        u.Email = 'standarduser@testorg.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LastName = 'Testing';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = p.Id;
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.Username = 'standar123456duser@testorg.com';
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        insert u;
       List <User> userlst = new List<User>([select Id,Business_Unit__c,Case_Owner__c from User where Id =: u.Id]);
       List<User> lstUserUpdate = new List<User>();
        Test.startTest();
        for(User user: userlst)
        {
            user.Business_Unit__c = 'Gypsum';
            user.Case_Owner__c = True;
            user.Id = u.Id;
            lstUserUpdate.add(user);
        }
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        //update u;  
        update lstUserUpdate;  
        Test.stopTest();
                
    }*/

}
GhanshyamChoudhariGhanshyamChoudhari
//Remove userInfoUpdate.add(UI); 
​//add below line
userInfoUpdate.add(UI.Weber_User_Id__c );

 
Siddharth LakhotiaSiddharth Lakhotia
it shows another error now..Method does not exist or incorrect signature: void add(String) from the type List<UserInformation__c>
Siddharth LakhotiaSiddharth Lakhotia
Any help on this one. ?