+ Start a Discussion
santhiya duraisanthiya durai 

unable to cover the code

Hi,
I tried a lot but unable to cover below part.

Class:
public class testclassgenerator {
      
    public class ProductWrapper{
        public String productName {get;set;}
        public String internalClass {get;set;}
        public String brandName{get;set;}
        public String OrderNumber {get;set;}
        public String SoldToName {get;set;}
        public String ShipToCountry {get;set;}
        public String DeliveryDate {get;set;}
        public String ProductNumber {get;set;}
        public String FactoryName {get;set;}
        public String DaysRem {get;set;}
        public String EarliestExpDate {get;set;}
        public String TestReportID {get;set;}
        public String CPC {get;set;}
        public String DOC {get;set;}
        public String ukDOC {get;set;}
        public String ResponsibleQE{get;set;}
        public String CPCDocId{get;set;}
        public String DOCDocId{get;set;}
        public String ukDOCDocId{get;set;}
        public Date testDate{get;set;}
        public String ProductId{get;set;}
        public String ReqId{get;set;}
        public String CustomerName{get;set;}
        public String resultType{get;set;}
        public String responsibleQEId{get;set;}
        public String TestingStatus{get;set;}
       
    }
   public void execute(String dataSet,List<sObject> sObjectList,String insightExternalObjectId,Integer partNumber)
    {
        System.debug('List=>'+sObjectList);
        if(!sObjectList.isEmpty())
        {
            List<ICIX_V1_Purchase_Order__c> lstOrder = new List<ICIX_V1_Purchase_Order__c>();
            Set<Id> stOd = new Set<Id>();
            Set<Id> proSt = new Set<Id>();
            Set<Id> accId = new Set<Id>();
            Set<Id> RISet = new Set<Id>();
            Set<Id> MajorProd = new Set<Id>();
            Set<Id> SetParentProd = new Set<Id>();
            Set<Id> SetChildProd = new Set<Id>();
            Set<String> prodNum = new Set<String>();
            Set<Id> HPISt = new Set<Id>();
            Boolean isReqExpBlank = false;
            Boolean isExtend = false;
            lstOrder.addAll((List<ICIX_V1_Purchase_Order__c>)sObjectList);
            List<ICIX_V1_UP_Relationship__c> lstUPRNew = new List<ICIX_V1_UP_Relationship__c>();
            //List<ICIX_V1__Request__c> lstRequest = new List<ICIX_V1__Request__c>();
            List<Product2> lstAllProducts = new list<Product2>();
            List<Date> lstdateReq = new List<Date>();
            List<ProductWrapper> wrapperList = new List<ProductWrapper>();
            List<Id> extendedProductIdsList = new List<Id>();
            for(ICIX_V1_Purchase_Order__c obOrder : lstOrder)
            {
                stOd.add(obOrder.Id);
                accId.add(obOrder.ICIX_V1_Trading_Partner__c);
            }
           
           
            set<Id> tradingPartnersId = new set<Id>();
            List<ICIX_V1_Purchase_Order_Line_Item__c> lstOrderItem = [SELECT Id,
                                                                      
                                                                       ICIX_V1_Purchase_Order__c,ICIX_V1_ICIX_Product__c,
                                                                       ICIX_V1_ICIX_Product__r.Product_Number__c,ICIX_V1_ICIX_Product__r.Name,
                                                                    
                                                                       ICIX_V1_ICIX_Product_Relationship__c,
                                                                    
                                                                       ICIX_V1_Status__c,ICIX_V1_Purchase_Order__r.ICIX_V1_Trading_Partner__c
                                                                       FROM ICIX_V1_Purchase_Order_Line_Item__c
                                                                       where ICIX_V1_Purchase_Order__c in : stOd];
            if(lstOrderItem.size() > 0)
            {
                for(ICIX_V1_Purchase_Order_Line_Item__c obItem : lstOrderItem)
                {
                    proSt.add(obItem.ICIX_V1_ICIX_Product__c);  
                    prodNum.add(obItem.ICIX_V1_ICIX_Product__r.Product_Number__c);
                    tradingPartnersId.add(obItem.ICIX_V1_Purchase_Order__r.ICIX_V1_Trading_Partner__c);
                }
            }
}
}
           

Test class:

@isTest
private class testclassgenerator_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
      //creating account
    Account account_Obj = new Account(Name = 'Name783', Type = 'Prospect', Facility_Name__c = 'Facil788', ICIX_V1_Status__c = 'Active', ICIX_V1_ICIX_ID__c = 'ICIX_480');
    Insert account_Obj;   
     
    // Creating Products      
    Product2 product2_Obj = new Product2(Name = 'Name381',Global_SKU__c = 'C1918', Manual_Product__c = true, Parent_Number__c = '21', Product_Number__c = '22', Product_Status__c = '23', ProductType__c = 'RETAILITEM', Responsible_QE__c = 'Picklist01');
    Insert product2_Obj; 
    Product2 product2_Obj1 = new Product2(Name = 'Name381', Global_SKU__c = 'C1918', Manual_Product__c = true, Parent_Number__c = '21', Product_Number__c = '22', Product_Status__c = '23', ProductType__c = '24', Responsible_QE__c = 'Picklist01');
    Insert product2_Obj1; 
        ICIX_V1_UP_Relationship__c icix_v1_up_relationship_Obj = new ICIX_V1_UP_Relationship__c(Name = 'Name842', Trading_Partner__c = account_Obj.id, ICIX_V1_Type__c = 'Sell', ICIX_V1_Status__c = 'Suspended', IXIX_V1_Product__c = product2_Obj.id);
    Insert icix_v1_up_relationship_Obj; 
    ICIX_V1_Attribute__c icix_v1_attribute_Obj = new ICIX_V1_Attribute__c(Name = 'Name409', ICIX_V1_Type__c = 'Attribute', ICIX_V1__c = 'Text', ICIX_V1_Relationship_Types_List__c = 'Product');
    Insert icix_v1_attribute_Obj; 
    ICIX_V1_Purchase_Order__c icix_v1_purchase_order_Obj = new ICIX_V1_Purchase_Order__c(Name = 'Name571', ICIX_V1_Trading_Partner__c = account_Obj.id, ICIX_V1_PO_Status__c = 'Open', ICIX_V1_PO_Number__c = 'ICIX_651', ICIX_V1_External_Id__c = 'ICIX_463');
    Insert icix_v1_purchase_order_Obj; 
    ICIX_V1_Purchase_Order_Line_Item__c icix_v1_purchase_order_line_item_Obj = new ICIX_V1_Purchase_Order_Line_Item__c(Name = 'Name824', ICIX_V1_Certificate_Generated__c = false, ICIX_V1_ICIX_Product__c = product2_Obj.id, ICIX_V1_ICIX_Product_Relationship__c = icix_v1_up_relationship_Obj.id, ICIX_V1_Purchase_Order__c = icix_v1_purchase_order_Obj.id, ICIX_V1_Quantity__c = 16, ICIX_V1_Status__c = 'Open', ICIX_V1_Test_Request_Trading_Partner__c = account_Obj.id);
    Insert icix_v1_purchase_order_line_item_Obj; 
    test.stopTest();
  }
  static testMethod void test_SyncRetailItemsQE_UseCase1(){
      List<ICIX_V1_UP_Relationship__c> icix_v1_up_relationship_Obj  =  [SELECT Id,Name,Trading_Partner__c,ICIX_V1_Type__c,ICIX_V1_Status__c,IXIX_V1_Product__c,Product_Type__c from ICIX_V1_UP_Relationship__c];
    System.assertEquals(true,icix_v1_up_relationship_Obj.size()>0);
    List<ICIX_V1_Attribute__c> icix_v1_attribute_Obj  =  [SELECT Id,Name,ICIX_V1_Type__c,ICIX_V1__c,ICIX_V1_Relationship_Types_List__c from ICIX_V1_Attribute__c];
    System.assertEquals(true,icix_v1_attribute_Obj.size()>0);
    List<ICIX_V1_Purchase_Order__c> icix_v1_purchase_order_Obj  =  [SELECT Id,Name,ICIX_V1_Trading_Partner__c,ICIX_V1_Test_Request_Trading_Partner__c,ICIX_V1_PO_Status__c,ICIX_V1_PO_Number__c,ICIX_V1_External_Id__c from ICIX_V1_Purchase_Order__c];
    System.assertEquals(true,icix_v1_purchase_order_Obj.size()>0);
    List<ICIX_V1_Purchase_Order_Line_Item__c> icix_v1_purchase_order_line_item_Obj  =  [SELECT Id,Name,ICIX_V1_Certificate_Generated__c,ICIX_V1_ICIX_Product__c,ICIX_V1_ICIX_Product_Relationship__c,ICIX_V1_Purchase_Order__c,ICIX_V1_Quantity__c,ICIX_V1_Status__c,ICIX_V1_Test_Request_Trading_Partner__c from ICIX_V1_Purchase_Order_Line_Item__c];
    System.assertEquals(true,icix_v1_purchase_order_line_item_Obj.size()>0);
      
    testclassgenerator obj01 = new testclassgenerator();
    obj01.execute('Test',new List<ICIX_V1_Purchase_Order_Line_Item__c>(),'test',1);
  }
}
AbhishekAbhishek (Salesforce Developers) 
Hi,

Try the suggestions as mentioned in the below developer discussion,

https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines


I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
santhiya duraisanthiya durai
@Abhishek .Thanks for your response.I already gone through the link which you shared. but it is not helping in my case