-3

One of my customer created below class. I have created a test class to cover but I am unable to cover the code. It seems I have created a correct data but it is not covering .Please anyone help me on this.

I am unable to cover getProducts(),UpdateQEs, SyncRetailItemsQE methods, It looks like I written correctly. I want someone review my code and help me if I missed anything Class:

public class MassQEController{
    public class prodwrap{
        public string ChildCount;
        public string Productname;
        public string Producttype;
        public String SFRecid;
        public string ProductNumber;
        public string Parentnumber;
        Public string Facility;
        public string Responsibleqe;
        public string UprId;
        public string Globalsku;
        public List<prodwrap> children;
    }
    @Auraenabled
    public static List<string> getAccounts(){
        List<ICIX_V1__Trading_Partner_Relationship__c> tprlist=[select id,ICIX_V1__Responder__r.Facility_Name__c,ICIX_V1__Responder__r.name from ICIX_V1__Trading_Partner_Relationship__c where ICIX_V1__Status__c='Active' and ICIX_V1__Type__c='Vendor' order by ICIX_V1__Responder__r.facility_name__c asc];
        List<String> str=new List<String>();
        for(ICIX_V1__Trading_Partner_Relationship__c tpr:tprlist ){
            if(tpr.ICIX_V1__Responder__r.Facility_Name__c!=null){
                str.add(tpr.ICIX_V1__Responder__r.Facility_Name__c);
            }
        }
        return str;
    }
@Auraenabled
    public static string getprods(string TradingPartnerName,string  parentnumber,string Globalsku,String Productnumber){
        List<ICIX_V1__UP_Relationship__c> uprlsts=new List<ICIX_V1__UP_Relationship__c>();
        set<String> strn=new set<String>();
        strn.add('ASSORTMENT');
        strn.add('SOLID');
        set<Id> pid=new set<Id>();
        if(parentnumber==''){
            parentnumber='XYZ';
        }
        if(Globalsku==''){
            Globalsku='XYZ';
        }
        if(Productnumber==''){
            Productnumber='XYZ';
        }
        if(TradingPartnerName!='No Trading Partner' && TradingPartnerName!= 'All Trading Partners'){
            uprlsts=[select id,ICIX_V1__Product__c,ICIX_V1__Product__r.GlobalSKU__c,ICIX_V1__Product__r.PRODUCTTYPE__c,ICIX_V1__Product__r.Parent_Number__c,ICIX_V1__Product__r.Name,ICIX_V1__Product__r.Product_Number__c,ICIX_V1__Related_Account__r.name,ICIX_V1__Related_Account__r.facility_name__c from ICIX_V1__UP_Relationship__c where ICIX_V1__Related_Account__r.Facility_Name__c=:TradingPartnerName and (ICIX_V1__Product__r.Parent_Number__c like: '%'+parentnumber+'%' or ICIX_V1__Product__r.GlobalSKU__c like: '%'+Globalsku+'%' or ICIX_V1__Product__r.Product_Number__c like: '%'+Productnumber+'%' ) and ICIX_V1__Product__r.PRODUCTTYPE__c in :strn];
        }
        else if(TradingPartnerName=='No Trading Partner'){
            uprlsts=[select id,ICIX_V1__Product__c,ICIX_V1__Product__r.GlobalSKU__c,ICIX_V1__Product__r.PRODUCTTYPE__c,ICIX_V1__Product__r.Parent_Number__c,ICIX_V1__Product__r.Name,ICIX_V1__Product__r.Product_Number__c,ICIX_V1__Related_Account__r.name,ICIX_V1__Related_Account__r.facility_name__c from ICIX_V1__UP_Relationship__c where ICIX_V1__Related_Account__c=null and (ICIX_V1__Product__r.Parent_Number__c like: '%'+parentnumber+'%' or ICIX_V1__Product__r.GlobalSKU__c like: '%'+Globalsku+'%' or ICIX_V1__Product__r.Product_Number__c like: '%'+Productnumber+'%' )  and ICIX_V1__Product__r.PRODUCTTYPE__c in :strn];
        }
        else if(TradingPartnerName == 'All Trading Partners'){
          uprlsts=[select id,ICIX_V1__Product__c,ICIX_V1__Product__r.GlobalSKU__c,ICIX_V1__Product__r.PRODUCTTYPE__c,ICIX_V1__Product__r.Parent_Number__c,ICIX_V1__Product__r.Name,ICIX_V1__Product__r.Product_Number__c,ICIX_V1__Related_Account__r.name,ICIX_V1__Related_Account__r.facility_name__c from ICIX_V1__UP_Relationship__c where ICIX_V1__Related_Account__c !=null AND (ICIX_V1__Product__r.Parent_Number__c like: '%'+parentnumber+'%' or ICIX_V1__Product__r.GlobalSKU__c like: '%'+Globalsku+'%' or ICIX_V1__Product__r.Product_Number__c like: '%'+Productnumber+'%' ) and ICIX_V1__Product__r.PRODUCTTYPE__c in :strn];
     
        }
        set<id> upids=new set<id>();
        for(ICIX_V1__UP_Relationship__c upr:uprlsts){
            upids.add(upr.id);
        }
        map<id,ICIX_V1__UP_Relationship_Attribute__c> map_upr=new map<id,ICIX_V1__UP_Relationship_Attribute__c>();
        List<ICIX_V1__UP_Relationship_Attribute__c> uprAttr=[select id,ICIX_V1__UP_Relationship__c,ICIX_V1__Attribute_Value__c from ICIX_V1__UP_Relationship_Attribute__c where ICIX_V1__UP_Relationship__c in:upids and ICIX_V1__Attribute__r.ICIX_V1__Type__c='Tag' ];
        for(ICIX_V1__UP_Relationship_Attribute__c up:uprAttr){
            map_upr.put(up.ICIX_V1__UP_Relationship__c,up);
        }
        List<prodwrap> prodwraplist=new List<prodwrap>();
        for(ICIX_V1__UP_Relationship__c upr: uprlsts ){
            prodwrap prwrp=new prodwrap();
            prwrp.Productname=upr.ICIX_V1__Product__r.Name;
            prwrp.UprId=upr.Id;
            prwrp.Producttype=upr.ICIX_V1__Product__r.PRODUCTTYPE__c;
            prwrp.SFRecid='/'+upr.ICIX_V1__Product__c;
            prwrp.ProductNumber=upr.ICIX_V1__Product__r.Product_Number__c;
            prwrp.Facility=UPR.ICIX_V1__Related_Account__r.Facility_name__c;
            prwrp.Parentnumber=upr.ICIX_V1__Product__r.Parent_Number__c;
            prwrp.Globalsku=upr.ICIX_V1__Product__r.GlobalSKU__c;
            if(map_upr.containskey(upr.id)){
                if(map_upr.get(upr.id).ICIX_V1__Attribute_Value__c!=null){
                    prwrp.Responsibleqe=map_upr.get(upr.id).ICIX_V1__Attribute_Value__c;
                }
            }
            prodwraplist.add(prwrp);
        }
        string ks=JSON.serialize(prodwraplist,true);
        string ns=ks.replace('children', '_children');
        system.debug(ns);
        return ns;
    }
    @Auraenabled
    public static string UpdateQEs(List<Id> UprIds , String ResponsibleQE ,String FacilityName ){
        System.debug('=========UprIds=========='+UprIds);
        System.debug('=========ResponsibleQE=========='+ResponsibleQE);
        System.debug('=========FacilityName=========='+FacilityName);
        list<ICIX_V1__UP_Relationship_Attribute__c> Upattr=[select id,ICIX_V1__Attribute__c from ICIX_V1__UP_Relationship_Attribute__c where ICIX_V1__UP_Relationship__c in:UprIds and ICIX_V1__Attribute__r.ICIX_V1__Type__c='Tag'];
        delete  Upattr;
        list<ICIX_V1__Attribute__c> attr=[select id,name from ICIX_V1__Attribute__c where name=:ResponsibleQE and ICIX_V1__type__c='Tag' limit 1];
        list<ICIX_V1__UP_Relationship_Attribute__c> Uprattriinsert=new list<ICIX_V1__UP_Relationship_Attribute__c>();
        list<ICIX_V1__UP_Relationship_Attribute__c> UprattriinsertAsst=new list<ICIX_V1__UP_Relationship_Attribute__c>();
        Id AttrId=attr[0].Id;
        system.debug('attribute'+attr);
        for(Id ids:UprIds){
            for(ICIX_V1__Attribute__c c:attr){
                ICIX_V1__UP_Relationship_Attribute__c a=new ICIX_V1__UP_Relationship_Attribute__c();
                a.ICIX_V1__UP_Relationship__c=ids;
                a.ICIX_V1__Attribute_Value__c=ResponsibleQE;
                a.ICIX_V1__Attribute__c=c.id;
                UprattriinsertAsst.add(a);
            }
        }   
        list<ICIX_V1__PP_Relationship__c> pprel=[select id,ICIX_V1__Product1__c,ICIX_V1__Product2__c from ICIX_V1__PP_Relationship__c where ICIX_V1__Product1__c in (select ICIX_V1__Product__c from ICIX_V1__UP_Relationship__c where Id in : UprIds)  and ICIX_V1__type__c='Component'];
        set<id> rids=new set<id>();
        for(ICIX_V1__PP_Relationship__c p:pprel){
            if(p.ICIX_V1__Product2__c !=null){
                rids.add(p.ICIX_V1__Product2__c );
            }
        }
        List<ICIX_V1__UP_Relationship__c> uprlsts = new List<ICIX_V1__UP_Relationship__c>();
        if(FacilityName == 'All Trading Partners'){
         uprlsts = [SELECT Id,ICIX_V1__Product__c,ICIX_V1__Related_Account__c FROM ICIX_V1__UP_Relationship__c WHERE ICIX_V1__Related_Account__r.Facility_Name__c != null AND  ICIX_V1__Product__c in : rids];   
        }
        else{
        uprlsts=[select id,ICIX_V1__Product__c from ICIX_V1__UP_Relationship__c where ICIX_V1__Related_Account__r.Facility_Name__c=:FacilityName and ICIX_V1__Product__c in : rids];
        }
        list<ICIX_V1__UP_Relationship_Attribute__c> UpattrRetailItems=[select id,ICIX_V1__Attribute__c,ICIX_V1__UP_Relationship__c from ICIX_V1__UP_Relationship_Attribute__c where ICIX_V1__UP_Relationship__c in:uprlsts and ICIX_V1__Attribute__c=:AttrId];
        system.debug('Existing Attributess==>'+UpattrRetailItems);
        set<Id> Alreadyexists=new set<Id>();
        for(ICIX_V1__UP_Relationship_Attribute__c uprAtt : UpattrRetailItems){
            Alreadyexists.add(uprAtt.ICIX_V1__UP_Relationship__c);
        }
        system.debug('Existing Attributess==>'+Alreadyexists);
        set<Id> ReIds=new set<Id>();
        set<Id> ReUpr=new set<Id>();
        for(ICIX_V1__UP_Relationship__c Upr:uprlsts){
            if(!Alreadyexists.contains(Upr.Id)){
                for(ICIX_V1__Attribute__c c:attr){
                    ICIX_V1__UP_Relationship_Attribute__c a=new ICIX_V1__UP_Relationship_Attribute__c();
                    a.ICIX_V1__UP_Relationship__c=Upr.Id;
                    a.ICIX_V1__Attribute_Value__c=ResponsibleQE;
                    a.ICIX_V1__Attribute__c=c.id;
                    ReIds.add(Upr.ICIX_V1__Product__c);
                    ReUpr.add(Upr.Id);
                    Uprattriinsert.add(a);
                }
            }else{
                ReIds.add(Upr.ICIX_V1__Product__c);
                ReUpr.add(Upr.Id);
            }
        }
        RecursivePreventer.recursiveFlag=false;
        if(UprattriinsertAsst.size()>0){
            system.debug('UPR Tgas'+UprattriinsertAsst);
            database.insert(UprattriinsertAsst,false);
        }
        if(Uprattriinsert.size()>0){
            // insert Uprattriinsert;
            system.debug('Retail Item tags'+Uprattriinsert);
            Database.SaveResult[] srList=database.insert(Uprattriinsert,false);
            for (Database.SaveResult sr : srList) {
                if (sr.isSuccess()) {
                    // Operation was successful, so get the ID of the record that was processed
                    System.debug('Successfully inserted account. Account ID: ' + sr.getId());
                }
                else {
                    // Operation failed, so get all errors                
                    for(Database.Error err : sr.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        System.debug(err.getStatusCode() + ': ' + err.getMessage());
                        System.debug('Account fields that affected this error: ' + err.getFields());
                    }
                }
            }
            system.debug('Calling Future Method');
            //Calling Future methods..Passing Retail Items Upr , Attribute Id and Facility Name as Parameters 
        } 
        if(FacilityName == 'All Trading Partners'){
       
             System.enqueueJob(new SyncRetailItemsQeQueueable(ReIds,ReUpr,AttrId,FacilityName));
        }
        else{
          MassQEController.SyncRetailItemsQE(ReIds,ReUpr,AttrId,FacilityName); 
        }
        return 'Updated successfully.';
    }
    //Asyncronous Processing of the Removal of Retail Items QE's
    @Future
    public static void SyncRetailItemsQE(set<Id> RetailId,set<Id> RetailUPRId,Id AttrId,string TradingPartnerName){
        system.debug('Retail Id==>'+RetailId);
        system.debug('Retail Id UPR==>'+RetailUPRId);
        system.debug('Retail Id UPR==>'+AttrId);
        system.debug('Trading Partner Name==>'+TradingPartnerName);
        list<ICIX_V1__PP_Relationship__c> pprel=[select id,ICIX_V1__Product1__c,ICIX_V1__Product2__c from ICIX_V1__PP_Relationship__c where ICIX_V1__Product2__c in :RetailId  and ICIX_V1__type__c='Component'];
        //map of Retail Item and Its Assortments...
        map<Id,List<Id>> MpRetailItemMap=new map<Id,List<Id>>();
        set<Id> AsstId=new set<Id>();
        for(ICIX_V1__PP_Relationship__c pp : pprel){
            if(pp.ICIX_V1__Product1__c!=null){
                //Adding All Assortment Product Id's in Set
                AsstId.add(pp.ICIX_V1__Product1__c);
                if(MpRetailItemMap.containskey(pp.ICIX_V1__Product2__c)){
                    list<Id> Aid=MpRetailItemMap.get(pp.ICIX_V1__Product2__c);
                    Aid.add(pp.ICIX_V1__Product1__c);
                    MpRetailItemMap.put(pp.ICIX_V1__Product2__c,Aid);
                }else{
                    list<Id> Aid=new List<Id>();
                    Aid.add(pp.ICIX_V1__Product1__c);
                    MpRetailItemMap.put(pp.ICIX_V1__Product2__c,Aid);
                }
            }
        }
        //Removing if any null is present
        AsstId.remove(null);
        //Querying the Attributes of the Retail Item Upr's
        list<ICIX_V1__UP_Relationship_Attribute__c> UpattrRetailItems=[select id,ICIX_V1__Attribute__c,ICIX_V1__Attribute__r.name,ICIX_V1__UP_Relationship__c,ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c from ICIX_V1__UP_Relationship_Attribute__c where ICIX_V1__UP_Relationship__c in:RetailUPRId and ICIX_V1__Attribute__r.ICIX_V1__type__c='Tag'];
        //Querying the Attributes of the Retail Item Upr's 
        list<ICIX_V1__UP_Relationship_Attribute__c> UpattrAst = new List<ICIX_V1__UP_Relationship_Attribute__c>();
        
       
         UpattrAst=[select id,ICIX_V1__Attribute__c,ICIX_V1__UP_Relationship__c,ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c,ICIX_V1__Attribute__r.name from ICIX_V1__UP_Relationship_Attribute__c where ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c in:AsstId and ICIX_V1__UP_Relationship__r.ICIX_V1__Related_Account__r.Facility_Name__c=:TradingPartnerName  and ICIX_V1__Attribute__r.ICIX_V1__type__c='Tag'];
           
       
            //Adding All the Assortment Id and list of Attribute names in the Map..Since an Assortment UPR contains only one Tag..unlike a Retail Item upr which can have multiple Tags of Responsible QE's.
        system.debug('Attribute Retail Items'+UpattrRetailItems);
        system.debug('Attribute Assortments==>'+UpattrAst);
        map<Id,List<String>> MpTag=new map<Id,List<String>>();
        for(ICIX_V1__UP_Relationship_Attribute__c uat :  UpattrAst){
            if(MpTag.containskey(uat.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c)){
                List<String> Strglst=MpTag.get(uat.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c);
                Strglst.add(uat.ICIX_V1__Attribute__r.name);
                MpTag.put(uat.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c,Strglst);
            }else{
                List<String> Strlst=new list<String>();
                Strlst.add(uat.ICIX_V1__Attribute__r.name);
                MpTag.put(uat.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c,Strlst);
            }
        }
        //Checking to Delete the Responsible QE tags of the Retail Items Upr's when it is not present in the Assortment UPR's of the Related Trading Partner..
        List<ICIX_V1__UP_Relationship_Attribute__c> ToDelete=new List<ICIX_V1__UP_Relationship_Attribute__c>();
        //Looping throgh the Retail Items UPR..
        for(ICIX_V1__UP_Relationship_Attribute__c uar : UpattrRetailItems){
            //Getting the Assortment under which the Retail Items are present..
            if(MpRetailItemMap.containskey(uar.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c)){
                List<Id> Aid=MpRetailItemMap.get(uar.ICIX_V1__UP_Relationship__r.ICIX_V1__Product__c);
                if(Aid.size()>0){
                    set<String> Strg=new set<String>();
                    system.debug('Assortment Ids==>'+Aid);
                    system.debug('Assortment Tags==>'+MpTag);
                    for(Id Ids : Aid){
                        if(MpTag.containskey(Ids)){
                            Strg.addAll(MpTag.get(Ids));
                        }
                    }
                    system.debug('Assortment Attributes==>'+Strg);
                    Strg.remove(null);
                    if(!Strg.contains(uar.ICIX_V1__Attribute__r.name)){
                        system.debug('To delete==>'+uar);
                        ToDelete.add(uar); 
                    }
                }
            }
        }
        system.debug('To delete the Attribytes==>'+ToDelete);
        //Deleting the Responsible QE tags which are not under any related Assortment Tags..
        Delete ToDelete;
    }

Test Class:

Public class MassQEController_Test{
   
 @testSetup
  static void setupTestData1(){
      try{
    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      
    ICIX_V1__ICIX_Product__c product2_Obj = new ICIX_V1__ICIX_Product__c(Name = 'Name381',GlobalSKU__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; 
    ICIX_V1__ICIX_Product__c product2_Obj1 = new ICIX_V1__ICIX_Product__c(Name = 'Name381', GlobalSKU__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; 
 
    //creating Attribute Group      
    ICIX_V1__Attribute_Group__c ixix_v1_attribute_group_Obj = new ICIX_V1__Attribute_Group__c(Name = 'Name546');
    Insert ixix_v1_attribute_group_Obj; 
          
    //Creating Attribute      
    ICIX_V1__Attribute__c icix_v1_attribute_Obj = new ICIX_V1__Attribute__c(Name = 'Name450', ICIX_V1__Attribute_Group__c = ixix_v1_attribute_group_Obj.id, ICIX_V1__Type__c = 'Tag', ICIX_V1__Relationship_Types_List__c = 'UU Relationship; UP Relationship; PP Relationship',ICIX_V1__Relationship_Types__c='UU Relationship; UP Relationship; PP Relationship');
    Insert icix_v1_attribute_Obj;
          
    //creating UP Relationship      
    ICIX_V1__UP_Relationship__c icix_v1_up_relationship_Obj = new ICIX_V1__UP_Relationship__c(Name = 'Name168',Id='a1v5w000003EvgyAAC', ICIX_V1__Related_Account__c = account_Obj.id, ICIX_V1__Type__c = 'Tag', ICIX_V1__Status__c = 'Active', ICIX_V1__Product__c = product2_Obj.id);
    //Insert icix_v1_up_relationship_Obj; 
    icix_v1_up_relationship_Obj.ICIX_V1__Product__c= product2_Obj.id;
    update icix_v1_up_relationship_Obj;
          
    //creating PP relationship      
    ICIX_V1__PP_Relationship__c icix_v1_pp_relationship_Obj = new ICIX_V1__PP_Relationship__c(Name = 'Name412', ICIX_V1__Product1__c = icix_v1_up_relationship_Obj.ICIX_V1__Product__c, ICIX_V1__Product2__c=product2_Obj.id,ICIX_V1__Type__c = 'Component');
    Insert icix_v1_pp_relationship_Obj; 
    icix_v1_pp_relationship_Obj.ICIX_V1__Product1__c= icix_v1_up_relationship_Obj.ICIX_V1__Product__r.id;
    update icix_v1_pp_relationship_Obj;
          
     //Creating UP Relationship Attribute     
    ICIX_V1__UP_Relationship_Attribute__c icix_v1_up_relationship_attribute_Obj = new ICIX_V1__UP_Relationship_Attribute__c(Name = 'Name532', ICIX_V1__Attribute__c = icix_v1_attribute_Obj.id, ICIX_V1__UP_Relationship__c = icix_v1_up_relationship_Obj.id, ICIX_V1__Attribute_Value__c = 'ICIX_613');
    Insert icix_v1_up_relationship_attribute_Obj; 
     
    //Creating Trading partner Relationship      
    list<ICIX_V1__Trading_Partner_Relationship__c> tradingpartnerrelationship=new list<ICIX_V1__Trading_Partner_Relationship__c>();
    ICIX_V1__Trading_Partner_Relationship__c tprelation=new ICIX_V1__Trading_Partner_Relationship__c (
    name='Hasbro Dev Stg Res 1',
    ICIX_V1__Status__c='Active',
    ICIX_V1__Type__c='Vendor',
    ICIX_V1__Responder__c=account_Obj.id);
    insert tprelation; 
    tradingpartnerrelationship.add(tprelation);
    insert tradingpartnerrelationship;      
    test.stopTest();
  }
      catch(Exception e){}
  }
 static testMethod void test_getprods_UseCase1(){
      try{
      
      
      MassQEController me=new MassQEController();
      MassQEController.getprods('TradingPartnerName', 'parentnumber', 'Globalsku', 'Productnumber');
      
      }catch(Exception e){}    
  }
        
   static testMethod void test_UpdateQEs_UseCase1(){
       try{
           
      list<ICIX_V1__Attribute__c> attr=[select id,name from ICIX_V1__Attribute__c where ICIX_V1__type__c='Tag' limit 1];
      List<ICIX_V1__UP_Relationship__c> uprlsts = [SELECT Id,ICIX_V1__Product__c,ICIX_V1__Related_Account__c FROM ICIX_V1__UP_Relationship__c WHERE ICIX_V1__Related_Account__r.Facility_Name__c != null];   
      list<ICIX_V1__UP_Relationship_Attribute__c> UpattrRetailItems=[select id,ICIX_V1__Attribute__c,ICIX_V1__UP_Relationship__c from ICIX_V1__UP_Relationship_Attribute__c];
      list<ICIX_V1__PP_Relationship__c> pprel=[select id,ICIX_V1__Product1__c,ICIX_V1__Product2__c from ICIX_V1__PP_Relationship__c where ICIX_V1__type__c='Component' and ICIX_V1__Product2__c!=null];

      MassQEController me=new MassQEController();
      MassQEController.UpdateQEs(new List<Id>(),'test data','test data');
      }catch(Exception e){}
   }
      
  static testMethod void test_SyncRetailItemsQE_UseCase(){
      
     List<ICIX_V1__ICIX_Product__c> product2_Obj  =  [SELECT Name,GlobalSKU__c,Manual_Product__c,Parent_Number__c,Product_Number__c,Product_Status__c,ProductType__c,Responsible_QE__c from ICIX_V1__ICIX_Product__c];
     System.assertEquals(true,product2_Obj.size()>0);
     List<ICIX_V1__UP_Relationship__c> icix_v1_up_relationship_Obj  =  [SELECT Id,Name,ICIX_V1__Related_Account__c,ICIX_V1__Type__c,ICIX_V1__Status__c,ICIX_V1__Product__c,Product_Type__c from ICIX_V1__UP_Relationship__c];
     System.assertEquals(false,icix_v1_up_relationship_Obj.size()>0);
     List<ICIX_V1__PP_Relationship__c> icix_v1_pp_relationship_Obj  =  [SELECT Id,Name,ICIX_V1__Product1__c,ICIX_V1__Product2__c,ICIX_V1__Type__c from ICIX_V1__PP_Relationship__c where ICIX_V1__Product1__c!=null];
     System.assertEquals(false,icix_v1_pp_relationship_Obj.size()>0);
     List<ICIX_V1__UP_Relationship_Attribute__c> icix_v1_up_relationship_attribute_Obj  =  [SELECT Id,Name,ICIX_V1__Attribute__c,ICIX_V1__UP_Relationship__c,Product_Number__c,Product_Id__c,Attribute_type__c,ICIX_V1__Attribute_Value__c from ICIX_V1__UP_Relationship_Attribute__c];
     System.assertEquals(false,icix_v1_up_relationship_attribute_Obj.size()>0);
    
     MassQEController obj01 = new MassQEController();
     MassQEController.SyncRetailItemsQE(new set<Id>(),new set<Id>(),'01p90000006uk2w','test data');
  }

}
  • 1
    It looks like you've been pointed to that resource (how do I increase code coverage) multiple times. Asking the same question over and over will end up leading to downvotes, and eventually the Stackexchange software will prevent you from asking any further questions. It's very important to be extremely detailed on this site. Providing your code is important, but only part of the story. You need to show us what you've tried, point to a specific place that you're stuck, and explain why the help/resources you've received before haven't helped. – Derek F Sep 9 at 11:41
  • Hi and welcome to SFSE. Could I suggest you spend a bit of time reading how to ask and then edit your question to provide specific detail about exactly where you are lacking coverage. As it stands this is a large amount of code that few people are going to want to analyse on your behalf. You need to provide clear and focused questions if you want to get help from the community. – Phil W Sep 9 at 11:43
  • I am unable to cover getProducts(),UpdateQEs, SyncRetailItemsQE methods, It looks like I written correctly. I want someone review my code and help me if I missed anything – Santhiya Sep 9 at 11:48
2

You're likely not getting coverage because you're using try-catch blocks in your unit test. Do not use try-catch in a unit test, unless you're specifically checking logic to ensure that your exception handlers are working correctly. Even then, do not catch Exception, but a specific exception that you're testing for.

If there was a wager going around, I'd bet that you have an exception in your unit test that you're try-catching into oblivion, thus making the test appear to succeed, but without coverage.

You will need to test getprods at least 3 times to cover all the possible branches. Your actual code contains unnecessary empty-list check guards and other bits that can be optimized away.

It's also possible that some of this code is unreachable as written. Remove the debug statements, and then remove the associated empty blocks of code that result.

If you're not going to handle errors, do not pretend to handle the errors:

        for (Database.SaveResult sr : srList) {
            if (sr.isSuccess()) {
                //
            }
            else {
                // Operation failed, so get all errors                
                for(Database.Error err : sr.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    System.debug(err.getStatusCode() + ': ' + err.getMessage());
                    System.debug('Account fields that affected this error: ' + err.getFields());
                }
            }

This will lead to hard-to-track situations. Either report an error up the stack, actually log the error in a permanent place (e.g. a custom object) for reporting/reviewing errors, or do not use the partial-success mechanism.

In summary, I wouldn't let this code anywhere near production until it's cleaned up, and you shouldn't, either.

Note that this answer alone won't fix your problems, but it will expose the underlying reasons why you're not getting the code coverage you expect.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.