+ Start a Discussion
Siddharth LakhotiaSiddharth Lakhotia 

First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call

@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();       
    }    
}

Hi,
I am getting error mentioned in subject line while running the test class. Any solution on this
Steven NsubugaSteven Nsubuga
 for(UserInformation__c UI : userInfoUpdate)
        {
            UI.Weber_User_Id__c = u.Id;
            
            userInfoUpdate.add(UI);
        }

That for loop needs fixing. Comment out or remove the line userInfoUpdate.add(UI);
@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();       
    }    
}

 
Siddharth LakhotiaSiddharth Lakhotia

Hi,

Code coverage for trigger comes 0% , post commenting of update command. 

 

Please find trigger for the test class
trigger OwerIdchane on User (after insert, after update) {
List<UserInformation__c> lstUserInfo = new List<UserInformation__c>();
for (User u : Trigger.New)
{
    if(u.Business_Unit__c == 'Weber' && u.Case_Owner__c == true)
    {
       UserInformation__c userInfo = UserInformation__c.getOrgDefaults();
       userInfo.Weber_User_Id__c = u.Id;
       //update userInfo;
       lstUserInfo.add(userInfo);   
    }
    else if(u.Business_Unit__c == 'Gypsum' && u.Case_Owner__c == true)
    {
        UserInformation__c userInfo = UserInformation__c.getOrgDefaults();
        userInfo.Gypsum_User_Id__c= u.Id;
        //update userInfo;
        lstUserInfo.add(userInfo); 
    }
}
 update lstUserInfo; 
}