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
CodeBeginnerCodeBeginner 

Need Help at test class

Hi I have developed the test class which should check for each parent record childs should have attachment and they need to be renamed and at parent level should contain 2 attachments and they need to be renamed. 

error message : System.ListException: Duplicate id in list: 0691l000000VZQHAA4

this error is coming from apex class which is containing set im wondered like how set contains duplicate IDs , can anyone help me here please trying since few days but not able to figure it out.

@isTest
private class SVMX_PS_FileTriggerHandlerTest {

    static testMethod void filesInsertTest() {
        
        //Create Account
        Account testAccount = SVMX_PS_TestUtil.createAccount(false);
        testAccount.SVMX_PS_ERP_Id__c = SVMX_PS_TestUtil.generateRandomString(16);
        insert testAccount;

        // create product
        Product2 prod = SVMX_PS_TestUtil.generateProduct();
        prod.ProductCode = SVMX_PS_TestUtil.generateRandomString(16);
        prod.SVMXC__Unit_Of_Measure__c = 'EA';
        insert prod;
        
        //Create Work Order
        SVMXC__Service_Order__c wo = SVMX_PS_TestUtil.createWorkOrder(testAccount.Id, 'New', false);
        wo.SVMXC__Order_Type__c='Field Service';
        wo.SVMXC__Street__c = '16260 Monterey St.';
        wo.SVMXC__City__c = 'Morgan Hill';
        wo.SVMXC__State__c = 'Arizona';
        wo.SVMXC__Zip__c = '95037';
        wo.SVMXC__Country__c = 'United States';
        wo.SVMXC__Priority__c = 'Medium';
        wo.RecordTypeId = SVMX_PS_AdvancedPricingCustomAction.WO_SERVICE_ORDER_RT;
        wo.SMAX_PS_Veolia_Business_Line__c = '12345';
        wo.SVMX_PS_ERP_Region__c = 'EMEA';
        insert wo;
        
        SVMXC__Service_Group__c SvcTeam = SVMX_PS_TestUtil.createServiceTeam(false);
        insert SvcTeam;
        
        SVMXC__Service_Group_Members__c Tech = SVMX_PS_TestUtil.createTechnician(false, SvcTeam.id);
        insert Tech;
        
      //  Id RTID = SVMX_PS_TestUtil.getRecordTypeId('SVMXC__Service_Order_Line__c.SVMXC.Products_Serviced');
        Id RTID = SVMX_PS_TestUtil.WDL_PRODUCTS_SERVICED_RT;
        
         SVMX_PS_VS_Part_Consumption_Settings__c partConsumptionSettings = new SVMX_PS_VS_Part_Consumption_Settings__c(name='Use Allocated Qty' );
         insert partConsumptionSettings;
         
        SVMXC__Service_Order_Line__c wd = SVMX_PS_TestUtil.createWorkDetailLine(wo.id, Tech.id, RTID, false);
        insert wd;
        
        ContentVersion cv = new ContentVersion(Title = 'Test_Do_Not_Remove', VersionData = Blob.valueof('Test Content Data'), IsMajorVersion = true,
                                              PathOnClient = 'Test.pdf');
        insert cv;
        
        ContentVersion cvlmra = new ContentVersion(Title = 'Test_Do_Not_Removelmra', VersionData = Blob.valueof('Test Content Data'), IsMajorVersion = true,
                                              PathOnClient = 'Test123.pdf');
        insert cvlmra;
        
        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument LIMIT 1];
            
        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId = wo.id;  
        contentlink.ShareType= 'I';               
        contentlink.ContentDocumentId=documents[0].Id;       
        contentlink.Visibility = 'AllUsers'; 
        insert contentlink;
        
         List<ContentDocument> document = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument  where Id NOT IN : documents LIMIT 1];
        
         ContentDocumentLink contentlinklmra=new ContentDocumentLink();
        contentlinklmra.LinkedEntityId = wo.id;  
        contentlinklmra.ShareType= 'I';               
        contentlinklmra.ContentDocumentId=document[0].Id; 
        contentlinklmra.Visibility = 'AllUsers'; 
        insert contentlinklmra;
        
        ContentVersion cv1 = new ContentVersion(Title = 'Test_Do_Not_Remove1', VersionData = Blob.valueof('Test Content Data1'), IsMajorVersion = true,
                                              PathOnClient = 'Test1.pdf');
        insert cv1;
        
        List<ContentDocument> documents1 = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument LIMIT 1];
            
        ContentDocumentLink contentlink1=new ContentDocumentLink();
        contentlink1.LinkedEntityId = wd.id;  
        contentlink1.ShareType= 'I';               
        contentlink1.ContentDocumentId=documents1[0].Id;
        contentlink1.Visibility = 'AllUsers'; 
        insert contentlink1;
        
        Test.startTest();

        SVMX_PS_FileRenameBatch myBatch = new SVMX_PS_FileRenameBatch();
        Database.executeBatch(myBatch);
        
        Test.stopTest();
        ContentDocumentLink reQueryCDLwdcheck = [SELECT ContentDocument.Title FROM ContentDocumentLink WHERE Id =: contentlink1.Id];    
        System.assertNotEquals(cv1.Title, reQueryCDLwdcheck.ContentDocument.Title);
        
        ContentDocumentLink reQueryCDL = [SELECT ContentDocument.Title FROM ContentDocumentLink WHERE Id =: contentlink.Id];    
        System.assertNotEquals(cv.Title, reQueryCDL.ContentDocument.Title);
        
        ContentDocumentLink reQueryCDLlmra = [SELECT ContentDocument.Title FROM ContentDocumentLink WHERE Id =: contentlinklmra.Id];    
        System.assertNotEquals(cvlmra.Title, reQueryCDLlmra.ContentDocument.Title);
        
        SVMXC__Service_Order__c reQueryWO = [SELECT SMAX_PS_Ready_for_Document_Merge__c FROM SVMXC__Service_Order__c WHERE Id =: wo.Id];
        System.assertEquals(true, reQueryWO.SMAX_PS_Ready_for_Document_Merge__c);
    }
}
Best Answer chosen by CodeBeginner
CodeBeginnerCodeBeginner
thanks i found answer