Skip to main content
In my class I am getting the object Id that in turns gets the User ID and uses that for a bunch of queries.  This works when I test it in SF, but somehow when I'm passing my ojbect over in the test class it doesn't see it.  I'm not sure what I'm doing wrong.

Thanks,

 

Id PlanId = ApexPages.currentPage().getParameters().get('id');

plan = [SELECT OwnerId FROM My_Plan__c WHERE Id = :PlanId];

userId = plan.OwnerId;

 

@isTest(SeeAllData=true)

Private class PersonalDashBoardTest {

@isTest static void TestPersonalDashBoard() {

PersonalDashTestData.createAccountWithOpps();

PersonalDashTestData.createGoals();

My_Plan__c plan = new My_Plan__c();

plan.Name = 'test 123';

insert(plan);

Test.startTest();

//Use the PageReference Apex class to instantiate a page

// PageReference pageRef = Page.AccountDashBoardPage; // name of the page goes here

//In this case, the Visualforce page named 'success' is the starting point of this test method.

// Test.setCurrentPage(pageRef);

//Instantiate and construct the controller class.

ApexPages.StandardController MyPlan = new ApexPages.StandardController(plan);

PersonalDashBoardClass controller = new PersonalDashBoardClass(MyPlan);

controller.getAccountSummary60();

controller.getAccountSummary90();

controller.getAcct60Total();

controller.getAcct90Total();

controller.getOpp60Total();

controller.getOpp90Total();

test.stopTest();

}

}

 
1 answer
  1. Feb 20, 2015, 10:00 PM

    Fixed it by adding the first line

    Apexpages.currentPage().getParameters().put('Id', plan.Id);

    ApexPages.StandardController MyPlan = new ApexPages.StandardController(plan);

    PersonalDashBoardClass controller = new PersonalDashBoardClass(MyPlan);

0/9000