Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a public page (http://uat-savantsystems.cs30.force.com/Customers/five9xmlresponder) which accepts two parameters. I attempt to call the page in my test class with the parameters as such:

PageReference vfPage = new PageReference('http://uat-savantsystems.cs30.force.com/Customers/five9xmlresponder');
vfPage.getParameters().put('pin', '1111111111');
vfPage.getParameters().put('cid', '2222222');

With no luck, in debug, param1 and 2 are null, so I tried the following:

PageReference vfPage = new PageReference('http://uat-savantsystems.cs30.force.com/Customers/five9xmlresponder?param1=1111111111&param2=2222222');

and ended up with the same results.

My custom controller is called by a VF page URL. Based on the parameters, the VF page displays different XML.

It seems like the VF page just isn't getting called by the test class. What am I doing wrong?

share|improve this question

2 Answers 2

You need to let the test framework know about your page so it can set the current page on your controller by using:

 Test.setCurrentPage(vfPage);

See Test Class.

share|improve this answer

This works for me, I hope it helps!

  PageReference tpageRef = Page.NameOfYourPageHere;
  Test.setCurrentPage(tpageRef);

  ApexPages.currentPage().getParameters().put('Id', po.Id);

  System.assertEquals( po.id,ApexPages.currentPage().getParameters().get('Id'));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.