I cannot get this controller's test class to pass at all. Please help me understand why I cannot write a test for ApexPages.currentPage().getParameters().get(). I assume the SOQL string should pass the test as I insert a record before it runs.


public class tablestagingController {

public ApexPages.StandardController controller;

public tablestagingController(ApexPages.StandardController controller) {
    this.controller = controller;

public PageReference saveanddirect() {

    String thfirstname = ApexPages.currentPage().getParameters().get('thfirstname');
    String thlastname = ApexPages.currentPage().getParameters().get('thlastname');


    Id recordid = controller.getId();
    String recordname = [SELECT id, Name FROM Reservation_Header__c WHERE id = :recordid].Name;

    PageReference a = new PageReference('http://test.force.com/reservetable/Staging_table_1?Name='+ recordid + '&00N1a000008FU6Z=' + thfirstname + '&00N1a000008FU6U=' + thlastname + '&00NP0000000nbCH=' + recordname);
    return a;


Test Class


public class testclasstablestaging{

public static testMethod void testtablestagingController(){

       Reservation_Header__c a = new Reservation_Header__c (First_Name__c = 'test1', Last_Name__c = 'test2', Phone__c = '703');
       insert a;

       PageReference pageRef1 = new PageReference('/apex/Reservation_Header_KFAK_5');
       apexpages.currentpage().getparameters().put('thfirstname' , a.First_Name__c);
       apexpages.currentpage().getparameters().put('thlastname' , a.Last_Name__c);

       ApexPages.StandardController c = new ApexPages.standardController(a);

       tablestagingController b = new tablestagingController(c);

       System.assert(b != null);

  • 2
    You need to call b.saveanddirect() from your test to get that code executed.
    – Keith C
    Mar 23, 2016 at 18:37
  • @KeithC Worked like a charm, can you post it as an answer so I may give you credit? Mar 23, 2016 at 19:11
  • Not sure much credit is deserved but adding an accepted answer avoids others looking at a question that is already solved.
    – Keith C
    Mar 23, 2016 at 19:16

1 Answer 1


You need to call b.saveanddirect() from your test to get that code executed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .