0

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());
4
  • What does protectEditedWorklogSubmissions do?
    – sfdcfox
    Commented Aug 4, 2021 at 18:44
  • If old record field value == 'Submitted' && updated record field value == 'Submitted' throw an error on submission. A record with the status value of 'Submitted' cannot be edited.
    – Sam
    Commented Aug 4, 2021 at 18:54
  • Hi Sam, I've linked what I think is relevant for you. Unit tests can't normally see production data. Make sure you're creating records in your unit test directly. See also Isolation of Test Data from Organization Data in Unit Tests.
    – sfdcfox
    Commented Aug 4, 2021 at 19:00
  • If this doesn't help, please let us know, we'll be happy to reopen your question for you. You may want to edit your question to include more information that distinguishes your question from the linked one.
    – sfdcfox
    Commented Aug 4, 2021 at 19:01

0

Browse other questions tagged .