+ Start a Discussion
Jim MontgomeryJim Montgomery 

add parameter to test class

I have this code in my page controller that allows for a "Select All" functionality.

public void selectAll() {
        if(allBool) {
            for(WrapperClass w : listWrapper) {
                w.checked = true;
            }
        } else {
            for(WrapperClass w : listWrapper) {
                w.checked = false;
            }

How do I pass that parameter to the test class?

 PageReference pageRef = page.Case_Inventory;
        pageRef.setRedirect(true);
    pageRef.getParameters().put('accountId',A.Id);
    pageRef.getParameters().put('CaseId',C.Id);
    pageRef.getParameters().put('All','True');
    test.setCurrentPage(pageRef);
    
      CaseInventory  CI = new CaseInventory();
            CI.selectAll();
Best Answer chosen by Jim Montgomery
Raj VakatiRaj Vakati
try this code
 
PageReference pageRef = page.Case_Inventory;
        pageRef.setRedirect(true);
    pageRef.getParameters().put('accountId',A.Id);
    pageRef.getParameters().put('CaseId',C.Id);
    pageRef.getParameters().put('All','True');
    test.setCurrentPage(pageRef);
    
      CaseInventory  CI = new CaseInventory();
	  CI.allBool =true ;
            CI.selectAll();

 

All Answers

Jim MontgomeryJim Montgomery
Getting error attempt to dereference a null object.
Raj VakatiRaj Vakati
try this code
 
PageReference pageRef = page.Case_Inventory;
        pageRef.setRedirect(true);
    pageRef.getParameters().put('accountId',A.Id);
    pageRef.getParameters().put('CaseId',C.Id);
    pageRef.getParameters().put('All','True');
    test.setCurrentPage(pageRef);
    
      CaseInventory  CI = new CaseInventory();
	  CI.allBool =true ;
            CI.selectAll();

 
This was selected as the best answer
Raj VakatiRaj Vakati
GIve me complete code 
Jim MontgomeryJim Montgomery
Raj Vakati Thank You!!!