• Upasana Mohapatra 14
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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;
    }
}

 
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;
    }
}