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
SFDC cloud  GuySFDC cloud Guy 

how to write code coverage for this code

public pagereference doAbandon(){
        return ctrl.doAbandon();
    } 
    public pagereference doIgnoreAction(){
        return ctrl.doIgnoreAction();
    } 
    public pagereference doViewCart(){
        return ctrl.doViewCart();
    } 
    public pagereference doConfigureOptions(){
        test_Config2__ProductAttributeValue__c attr = getAttributeValueSO();
        system.debug('CV Testing');
        if (attr.Apts_AP_Count__c > 0) {
            Set<String> ProductCodes = new Set<String>();
            List<License_Qty_Value__c> Licensees = [select Id,Product__c, Qty__c, High_Num__c, Low_Num__c, Product_Code__c FROM License_Qty_Value__c ORDER BY High_Num__c DESC];
            Decimal RemainingQty = attr.Apts_AP_Count__c;
            for (License_Qty_value__c myLicense :Licensees){
                system.debug('remaining qty ' + RemainingQty + ' High_Num__c ' + myLicense.High_Num__c + 'low num ' + myLicense.Low_Num__c);
                if ((RemainingQty <= myLicense.High_Num__c) && (RemainingQty >= myLicense.Low_Num__c)&&(myLicense.Product__c == 'AP')){
                    ProductCodes.add(myLicense.Product_Code__c);
                    RemainingQty = RemainingQty - myLicense.Qty__c;
                    System.debug('I am looking for '+myLicense.Product_Code__c);
                    if (RemainingQty <= 0)
                        break;
                }
            }
            if (attr.Apts_Policy_Enforcement_Firewall_License__c == 'Yes'){
                RemainingQty = attr.Apts_AP_Count__c;
                for (License_Qty_value__c myLicense :Licensees){
                    if ((RemainingQty < myLicense.High_Num__c) && (RemainingQty >= myLicense.Low_Num__c)&&(myLicense.Product__c == 'PEF')){
                        ProductCodes.add(myLicense.Product_Code__c);
                        RemainingQty = RemainingQty - myLicense.Qty__c;
                        System.debug('I am looking for '+myLicense.Product_Code__c);
                        if (RemainingQty <= 0)
                            break;
                    }
                }
            }
          
            List<test_CPQApi.CPQ.ProductOptionComponentDO> prodOptCompDOList = new List<Apttus_CPQApi.CPQ.ProductOptionComponentDO>();
           
            if(line.Apttus_Config2__PriceListId__c != null && line.id != null) {
                //Replace li id with product id
                test_CPQApi.CPQ.ProductOptionGroupSearchResultDO opGrpRespDO = Apttus_CPQApi.CPQWebService.getOptionGroupsForPriceListProduct(line.test_Config2__PriceListId__c, line.test_Config2__ProductId__c);
                if(opGrpRespDO.HasOptionGroups) {
                    system.debug('I have option groups');
                    List<test_CPQApi.CPQ.ProductOptionGroupDO> optionGroupList = opGrpRespDO.OptionGroups;
                    for (test_CPQApi.CPQ.ProductOptionGroupDO productGroup :optionGroupList) {
//                    test_CPQApi.CPQ.ProductOptionGroupDO prodOptGrpDO = prodOptGrpDOList[0];
                        if(productGroup.HasOptionComponents) {
                            List<test_CPQApi.CPQ.ProductOptionComponentDO> componentList = productGroup.OptionComponents;
                            for (test_CPQApi.CPQ.ProductOptionComponentDO component :componentList){
                                if (ProductCodes.contains(component.ProductCode))
                                    prodOptCompDOList.add(component);
                            }
                        }
                    }
                }

                List<test_CPQApi.CPQ.SelectedOptionDO> selectedOptDOList = new List<test_CPQApi.CPQ.SelectedOptionDO>();
                for(test_CPQApi.CPQ.ProductOptionComponentDO prodOptCompDO :prodOptCompDOList ) {
                        test_CPQApi.CPQ.SelectedOptionDO selectedOptDO = new test_CPQApi.CPQ.SelectedOptionDO();
                        selectedOptDO.ComponentId = prodOptCompDO.ComponentId;
                        selectedOptDO.ComponentProductId = prodOptCompDO.ComponentProductId;
                        selectedOptDO.Quantity = 1;
                        selectedOptDOList.add(selectedOptDO);
                }
              test_CPQApi.CPQ.AddOptionsResponseDO addOptRespDO = test_CPQApi.CPQWebService.addOptions(line.test_Config2__ConfigurationId__c, line.test_Config2__LineNumber__c.intValue(), selectedOptDOList);
            }
        }

        return ctrl.doConfigureOptions();
Hargobind_SinghHargobind_Singh
Hi, 

Hope you have gone through this article and relevant topics: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods. 


Thx.