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
Upasana Mohapatra 14Upasana Mohapatra 14 

Test Class help needed ** URGENT **

Hello All,
I have been banging my head trying to write the test class for the below code snipet. Appreciate anybody's help in this regard.
 
public class XYZ_RedirectToOptionsPageController {

    public XYZ_RedirectToOptionsPageController(ApexPages.StandardController controller) {

    }

    
    String callerPage;
    String configRequestId;
    public String id {get;set;}
    String detailCallerPage;
    String flow;
    public String refererStr { get;set; }
    public String liteItemId { get;set; }
    
    
    public XYZ_RedirectToOptionsPageController() {
        callerPage = ApexPages.CurrentPage().getParameters().get('callerPage');
        configRequestId = ApexPages.CurrentPage().getParameters().get('configRequestId');
        id = ApexPages.CurrentPage().getParameters().get('id');
        detailCallerPage = ApexPages.CurrentPage().getParameters().get('detailCallerPage');
        flow = ApexPages.CurrentPage().getParameters().get('flow');
        refererStr = ApexPages.currentPage().getHeaders().get('Referer');
        System.debug('Id'+id);
        liteItemId = [Select Id from ABC_Config2__LineItem__c where ABC_Config2__ConfigurationId__c = :id 
            AND ABC_Config2__IsPrimaryLine__c = true 
            AND ABC_Config2__LineType__c = 'Product/Service' Order By Id desc Limit 1 ].Id;
         System.debug('liteItemId'+liteItemId);        
    }
    
    public void executeLineItemsLogic() {
       if(String.isBlank(id)) return;
       List<ABC_Config2__LineItem__c> lineItemList = [SELECT Id, ABC_Config2__LineType__c, ABC_Config2__ChargeType__c, ABC_Config2__LineStatus__c, 
                ABC_Config2__EndDate__c, ABC_Config2__AssetLineItemId__c, ABC_Config2__AssetLineItemId__r.ABC_Config2__EndDate__c,
                ABC_Config2__PriceType__c, ABC_Config2__AssetQuantity__c, ABC_Config2__ConfigurationId__c,
                ABC_Config2__AssetLineItemId__r.ABC_Config2__ProductId__c, ABC_Config2__Quantity__c, 
                ABC_Config2__AttributeValueId__c, XYZ_Amend_Reason__c, 
                ABC_Config2__AssetLineItemId__r.ABC_Config2__Quantity__c, 
                ABC_Config2__AssetLineItemId__r.XYZ_Maximum_Licenses__c, BundleLineStatus__c,
                ABC_Config2__PriceListItemId__c, ABC_Config2__PriceListItemId__r.ABC_Config2__PriceType__c 
                FROM ABC_Config2__LineItem__c WHERE ABC_Config2__ConfigurationId__c = :id
                AND ABC_Config2__LineStatus__c = 'Existing' AND ABC_Config2__PriceListItemId__c != null
                AND ABC_Config2__AssetLineItemId__c != null AND BundleLineStatus__c = 'Amended'
                ORDER BY ID];

       if(lineItemList.isEmpty()) return;  
      
       for(ABC_Config2__LineItem__c lineItem : lineItemList) {
           if(lineItem.ABC_Config2__AssetQuantity__c < lineItem.ABC_Config2__AssetLineItemId__r.XYZ_Maximum_Licenses__c) {
               
               lineItem.ABC_Config2__Quantity__c = lineItem.ABC_Config2__AssetLineItemId__r.XYZ_Maximum_Licenses__c;
               lineItem.ABC_Config2__AssetQuantity__c =  lineItem.ABC_Config2__Quantity__c;
               lineItem.XYZ_Amend_Reason__c = null;
           }
       }
       
       update lineItemList;      
       
       
    }
    
    //action method to execute update logic and redirect to the option page
    public pageReference redirectToOptionPage() {
        executeLineItemsLogic();
        
        PageReference optionsPage = Page.ABC_Config2__ConfigureBundle;
        //optionsPage.getParameters().put('callerPage', callerPage);
        optionsPage.getParameters().put('configRequestId', configRequestId);
        optionsPage.getParameters().put('id', liteItemId);
        //optionsPage.getParameters().put('detailCallerPage', detailCallerPage);
        //optionsPage.getParameters().put('flow', flow);
         
        return optionsPage;
    }
}

 
KevinPKevinP
what part of this code are you trying to test, and what issues are you having? can you post your test as written? You'll find people here are generally unwilling to "do your homework for you" but if you have specific questions and are willing to show your work, as it were, you'll get a much more forthright response.
Upasana Mohapatra 14Upasana Mohapatra 14
//action method to execute update logic and redirect to the option page
    public pageReference redirectToOptionPage() {
        executeLineItemsLogic();
        
        PageReference optionsPage = Page.ABC_Config2__ConfigureBundle;
        //optionsPage.getParameters().put('callerPage', callerPage);
        optionsPage.getParameters().put('configRequestId', configRequestId);
        optionsPage.getParameters().put('id', liteItemId);
        //optionsPage.getParameters().put('detailCallerPage', detailCallerPage);
        //optionsPage.getParameters().put('flow', flow);
         
        return optionsPage;
    }
}

Unable to cover this part of my class in the test class. any help is highly appreciated.