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! Aug 24, 2015 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, 2015 at 21:14

1 Answer 1


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.

  • 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, 2015 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, 2015 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? Mar 4, 2019 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, 2019 at 17:45
  • These methods are useful when you have some trigger condition that checks for the current page in context. If it's not a specific page, don't run the trigger. So then, to test the trigger, you need to set the page in context during the test. Jan 21, 2021 at 19:38

You must log in to answer this question.

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