I'm trying to create a page in my test class like this:
PageReference pageRef = Page.testPage; Test.setCurrentPage(pageRef);
But I'm getting an error:
Compilation error: Page testPage does not exist.
What I'm doing wrong here?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI'm trying to create a page in my test class like this:
PageReference pageRef = Page.testPage; Test.setCurrentPage(pageRef);
But I'm getting an error:
Compilation error: Page testPage does not exist.
What I'm doing wrong here?
"Page.testPage"
The highlighted text should always be name of valid VF page. We use this as a reference while covering the corresponding controller class. VF page cannot be created in context of Test Class.
To test a controller, for the most part, you never need to call Test.setCurrentPage
at all. In fact I have never needed to do so, because even when I am parsing parameters from ApexPages.currentPage
, I do not actually care what its URL is. It's a fairly esoteric function.