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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a apex class in which I used current page name for some purpose.Now while creating a Test class for that I need to create a virtual visual Force page.So how to create that page in test class.


share|improve this question

Get the page reference using -

PageReference vfPageRef= Page.vfPageName; 

and set current PageReference for the controller. -

share|improve this answer

You set the current page ref as the page you are testing.

PageReference pageRef = Page.success; 
share|improve this answer

Do you need to write your test code on current page? set current page using following code..

public static testMethod void testMyController()

PageReference pageRef = Page.YourPageName;


/* Your code for test coverage */

share|improve this answer

Your Answer


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.