I am trying to implement the sboject clone() method in my test code and cannot get it to work properly. The code test if a service class performs as expected (record can not be edited if status is == 'Submitted') Here is my code:
List<Worklog__c> oldWorklogs = [SELECT Id, Description_Of_Work__c, Worklog_Status__c FROM Worklog__c WHERE Worklog_Status__c = 'Submitted' LIMIT 1];
Map<Id, Worklog__c> newWorklogs = new Map<Id, Worklog__c>();
for(Worklog__c wl : oldWorklogs) {
newWorklogs.get(wl.Id).put(wl.clone(true,true,true,true));
}
List<Worklog__c> worklogsWithErrors = WorklogStatusValidationService.protectEditedWorklogSubmissions(oldWorklogs, newWorklogs);
System.assertEquals(1, worklogsWithErrors.size(), 'Number of errored logs expected: 1 Logs found: ' + worklogsWithErrors.size());