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
ponneri navadeepponneri navadeep 

i want test class for this controller?please help me?

public class Core_IPS_Case_List_View_Export { 

    public static final integer MAX_EXPORT_ROWS = 10000;

    public Boolean isPDFExportActive { get; set; }

    public Boolean isExcelExportActive { get; set; }

    public String contentType { get; set; } 

    public String renderType { get; set; }

    public List<List<Case>> lstlstCase { get; set; }

    public String reportDate { get; set; }

    public String filterName { get; set; }

    private List<Case> lstCase;
    private String returnURL;
    private ApexPages.StandardSetController sscController;

    public Core_IPS_Case_List_View_Export(ApexPages.StandardSetController controller) {

        System.debug('#01 controller.getResultSize(): ' + controller.getResultSize());

        returnURL = ApexPages.CurrentPage().getUrl();

        // For Excel:
        contentType = 'application/vnd.ms-excel#Cases.xls';
        renderType  = '';

        // For PDF:
        // contentType = 'application/pdf#Cases.pdf';
        // renderType  = 'PDF';

        Datetime dtNow = Datetime.now();
        reportDate = dtNow.format('yyyy-MM-dd h:mm a');

        sscController = controller;
        sscController.setPageSize(1000);

        lstlstCase = new List<List<Case>>();
        
        String strfilterId = sscController.getFilterId();
        List<System.SelectOption> lstSelectOption = sscController.getListViewOptions();
        for (System.SelectOption so : lstSelectOption)
            if (so.getValue() == strfilterId) { 
                filterName = so.getLabel();            
                break;
            }

        isPDFExportActive   = false;
        isExcelExportActive = (sscController.getResultSize() < MAX_EXPORT_ROWS);

        System.debug('#01 sscController.getResultSize(): ' + sscController.getResultSize());
        if (sscController.getResultSize() >= MAX_EXPORT_ROWS) { 
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Maximum export size of ' + MAX_EXPORT_ROWS + ' cases exceeded.');
            ApexPages.addMessage(myMsg);
        }            
        
    }
    
    
    public PageReference returnToPage() {
    
        PageReference returnPage;
    
        Boolean portalUser = Core_IPS_Case_Comments_Handler.isCurrentUserPortalUser();
        if (portalUser)                    
            returnPage = new PageReference('/IPS/500/o');
        else    
            returnPage = new PageReference('/500/o');
            
        returnPage.setRedirect(true);
        return returnPage;
    }      
    
    
    private void loadCaseData() {
        Set<Id> setCaseId = new Set<Id>();                
        while(true) {
                
            for(Case cs : (List<Case>)sscController.getRecords())
                setCaseId.add(cs.Id);
            System.debug('#02 setCaseId: ' + setCaseId);

            lstCase = [SELECT Id, CaseNumber, Account.Name, Core_IPS_Project_Case__r.Name, Contact.Name, 
                              Subject, Status, Core_Sub_Status__c, Core_Severity__c, Product.Name, 
                              CreatedDate, LastModifiedDate, Core_IPS_Legacy_IPS_ID__c                               
                       FROM Case 
                       WHERE Id IN :setCaseId
                       ORDER BY CaseNumber];           

            lstlstCase.add(lstCase);

            if (lstlstCase.size() == 10)
                break;

            if (!sscController.getHasNext())
                break;
                
            setCaseId.clear();
            sscController.next();
        }     
    }
    
    public PageReference exportToExcel() {

        try {
            loadCaseData();
        }
        catch (Exception e) {
            String consolidatedMessage = e.getTypeName() + ' on line# ' + e.getLineNumber() + ' : ' + e.getMessage();
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, consolidatedMessage);
            ApexPages.addMessage(myMsg);
            return null;
        }

        PageReference excelPage = page.Core_IPS_Case_List_View;
        excelPage.setRedirect(false);
        return excelPage;
    }      
    
}