I noticed that there are two methods in the Test class, looks like for the same purpose:

public static Void setCurrentPage(PageReference page)
public static Void setCurrentPageReference(PageReference page)

The description of these two methods also same..Is there any difference?

I am using setCurrentPage in my test classes and everything is working fine.

  • 1
    Found them to be identical for all intents and purposes but very curious! – bigassforce Aug 24 '15 at 21:09
  • 1
    They are both worthless as you pretty much never care what the current page is, so much as what its parameters are. – Adrian Larson Aug 24 '15 at 21:14

There's no functional difference between the two functions, and since salesforce.com doesn't even erect a full Visualforce stack during Unit Tests, there's no real purpose in using either function right now. Hopefully, in the future, this function will serve some real purpose.

| improve this answer | |
  • I do use the Test.setCurrentPage method to pass the parameters to the test class..Not sure if you meant something else. – javanoob Aug 24 '15 at 22:31
  • 1
    @javanoob You can do ApexPages.currentPage().getParameters()... to set the parameters. So again, those other functions are equally redundant. – sfdcfox Aug 24 '15 at 22:33
  • I have found that using ApexPages.getCurrentPage() while executing a test fails if you have not first called Test.setCurrentPage(). Are you saying that there is another preferred way of setting the active page during the test? Note this is on Winter 19, so perhaps these functions do serve a purpose now? – Michael Erickson Mar 4 '19 at 17:38
  • @MichaelErickson I'll experiment. Previously, they did nothing significant, so maybe something has changed since. It may also be version dependent. – sfdcfox Mar 4 '19 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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