+ Start a Discussion
Frances AllenFrances Allen 

Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

I know that this error is referring my user update in line 14, but appears to be a mistake that is actually masking another mistake as I've already identified the user id with contact id in my code.

My full error upon deployment is :  
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Stack Trace: Class.IncompleteWorkshopLogsTest.testOnlyIncompleteWorkshopsReturned: line 14, column 1

Line 14  is 
update u;
The controller is here: 
@isTest
public class IncompleteWorkshopLogsTest {

   @isTest
   private static void testOnlyIncompleteWorkshopsReturned() {
       
       //create contact
       Contact c = new Contact(FirstName='Test', LastName = 'Test');
       insert c;
       
       User u = new User();
       u.ContactId = c.Id;
       
       update u; 
       
       //tie teaching to a volunteer and contact id 
       Workshop_Signup__c incompleteLog = new Workshop_Signup__c(
           Volunteer__c = c.Id    
       );
       
       insert incompleteLog;

       Workshop_Signup__c completeLog = new Workshop_Signup__c(
           Volunteer__c = c.Id
       );
       
       insert completeLog;

       //create and insert a workshop log that would indicate one finished vs. unfinished
       Workshop_log__c unfinished = new Workshop_log__c(RCM_A9__c = '');
       Workshop_log__c finished = new Workshop_log__c(RCM_A9__c = 'Complete');
       
       // tie workshop log to teaching record 
       incompleteLog.Id = unfinished.Id;
       completeLog.Id = finished.Id;
       insert  unfinished;
       insert  finished;
       
       insert new List<Workshop_Signup__c> { completeLog, incompleteLog };
        

       Test.startTest();

       IncompleteWorkshopLogs controller = new IncompleteWorkshopLogs();

       List<Workshop_Signup__c> results = controller.getTeaching();
       
       update results;

       Test.stopTest();

       System.assertEquals(1, results.size());
       System.assertEquals('Complete', results[0].Workshop_Log_Status__c);
      
   }
}

Tests have been a major roadblock in getting things deployed here, so any assistance would be appreciated.

Thanks, 

Frances 

  
Raj VakatiRaj Vakati
The problem in your code is the way you are updating the portal user is wrong .. Sample code is here below 
@isTest
public class IncompleteWorkshopLogsTest {

   @isTest
   private static void testOnlyIncompleteWorkshopsReturned() {
       
	   
	   UserRole portalRole = [Select Id From UserRole Where PortalType = 'None' Limit 1];
 
Profile profile1 = [Select Id from Profile where name = 'System Administrator'];
User portalAccountOwner1 = new User(
UserRoleId = portalRole.Id,
ProfileId = profile1.Id,
Username = System.now().millisecond() + 'test2@test.com',
Alias = 'batman',
Email='bruce.wayne@wayneenterprises.com',
EmailEncodingKey='UTF-8',
Firstname='Bruce',
Lastname='Wayne',
LanguageLocaleKey='en_US',
LocaleSidKey='en_US',
TimeZoneSidKey='America/Chicago'
);
Database.insert(portalAccountOwner1);

 
System.runAs ( portalAccountOwner1 ) {
 Account portalAccount1 = new Account(
Name = 'TestAccount',
OwnerId = portalAccountOwner1.Id
);
Database.insert(portalAccount1);

//Create contact
Contact contact1 = new Contact(
FirstName = 'Test',
Lastname = 'McTesty',
AccountId = portalAccount1.Id,
Email = System.now().millisecond() + 'test@test.com'
);
Database.insert(contact1);

//Create user
Profile portalProfile = [SELECT Id FROM Profile Limit 1];
User user1 = new User(
Username = System.now().millisecond() + 'test12345@test.com',
ContactId = contact1.Id,
ProfileId = portalProfile.Id,
Alias = 'test123',
Email = 'test12345@test.com',
EmailEncodingKey = 'UTF-8',
LastName = 'McTesty',
CommunityNickname = 'test12345',
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US'
);
Database.insert(user1);
}


  Workshop_Signup__c incompleteLog = new Workshop_Signup__c(
           Volunteer__c = c.Id    
       );
       
       insert incompleteLog;

       Workshop_Signup__c completeLog = new Workshop_Signup__c(
           Volunteer__c = c.Id
       );
       
       insert completeLog;

       //create and insert a workshop log that would indicate one finished vs. unfinished
       Workshop_log__c unfinished = new Workshop_log__c(RCM_A9__c = '');
       Workshop_log__c finished = new Workshop_log__c(RCM_A9__c = 'Complete');
       
       // tie workshop log to teaching record 
       incompleteLog.Id = unfinished.Id;
       completeLog.Id = finished.Id;
       insert  unfinished;
       insert  finished;
       
       insert new List<Workshop_Signup__c> { completeLog, incompleteLog };
	   
	  
       Test.startTest();

       IncompleteWorkshopLogs controller = new IncompleteWorkshopLogs();

       List<Workshop_Signup__c> results = controller.getTeaching();
       
       update results;

       Test.stopTest();

       System.assertEquals(1, results.size());
       System.assertEquals('Complete', results[0].Workshop_Log_Status__c); 
	   
}
	   
       //create contact
      
       
       //tie teaching to a volunteer and contact id 
     
        

      
   }
}

 
Om PrakashOm Prakash
You are trying to update a new user instance without id field.
Is it required to update the user, then question is which user should update?
If trying to crete new community user then use insert after putting  mandatory field instead of update at line 14.