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
richfer_rightrichfer_right 

How to write test method for this page reference?

How to write test method for this page reference?

 

public List<Project_Task__c> taskNameChangeToQAList {get;set;}
public PageReference taskNameChangeToQA() {

taskNameChangeToQAList=[select Status__c,List__c from Project_Task__c where Id=:ApexPages.currentPage().getParameters().get('projectTaskId')];
taskNameChangeToQAList[0].Status__c ='QA';
taskNameChangeToQAList[0].List__c ='QA';
update taskNameChangeToQAList;
return null;
}

public List<Project_Task__c> taskNameChangeToFinishList {get;set;}
public PageReference taskNameChangeToFinish() {

taskNameChangeToFinishList=[ select Status__c,List__c from Project_Task__c where Id=:ApexPages.currentPage().getParameters().get('projectTaskId')];
taskNameChangeToFinishList[0].Status__c ='finished';
taskNameChangeToFinishList[0].List__c ='Finished';
update taskNameChangeToFinishList;
return null;
}

Best Answer chosen by Admin (Salesforce Developers) 
Jeff MayJeff May

something along these lines:

 

@isTest
static void myTest(){
 
   // you might need to query or create a record to pass to the page

   // load the page 
   PageReference pageRef = Page.yourPage;
   pageRef.getParameters().put('yourparam',paramvalue);
   Test.setCurrentPageReference(pageRef);

   // create the controller instance
   thecontroller thec = new thecontroller(new ApexPages.StandardController(yourObj));

   // call controller methods        
   opse.updateAvailableList();
}