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.

In the documentation for testing controllers and extensions, there's a statement that references a Page object, but I've been unable to find where this is located elsewhere in the documentation. Where could I find more information on this object? In addition, what does Page.success mean?

Here's the example from the documentation:

public class thecontrollerTests {
    public static testMethod void testMyController() {
        PageReference pageRef = Page.success; // -------- What does Page.success mean?
        Test.setCurrentPage(pageRef);

        thecontroller controller = new thecontroller();
        String nextPage = controller.save().getUrl();

        // Verify that page fails without parameters
        System.assertEquals('/apex/failure?error=noParam', nextPage);

        // Add parameters to page URL
        ApexPages.currentPage().getParameters().put('qp', 'yyyy');

        // Instantiate a new controller with all parameters in the page
        controller = new thecontroller(); 
        controller.setLastName('lastname');
        controller.setFirstName('firstname');
        controller.setCompany('acme');
        controller.setEmail('firstlast@acme.com');
        nextPage = controller.save().getUrl();

        // Verify that the success page displays
        System.assertEquals('/apex/success', nextPage);
        Lead[] leads = [select id, email from lead where Company = 'acme'];
        System.assertEquals('firstlast@acme.com', leads[0].email);
    }
}
share|improve this question
2  
The PageReference class has some information about it (salesforce.com/us/developer/docs/pages/Content/…). In your case, "success" is the name of an existing page. Taken from your link "The controller calls two additional pages: a success page and a failure page. The text of those pages is not important for this example. They merely have to exist." –  Brad Ullery Jan 30 '13 at 15:39
add comment

3 Answers

up vote 1 down vote accepted

You can access all visualpages through the Page keyword, Page.pagename will return a PageReference (url datatype with some extras) to the page.

You can also use it through Visualforce

<apex:outputLink value="{!$Page.otherPage}">
    This is a link to another page.
  </apex:outputLink>

As far as i know it is also only documented through Visualforce use under the Global Variables

share|improve this answer
    
So, is "Success" the name of a Visualforce page? –  Matt K Jan 30 '13 at 15:34
2  
Yes indeed it is. If you go to Setup > Develop > Pages you will see Visualforce pages listed with Labels and Names. Using this convention is good practice as the platform enforces referential integretity. Meaning if you attempt to delete the page it will stop you and inform you which parts of your code reference it. There are also benefits in respect to avoiding namespace issues when packaging and deploying your solution to this approach. –  Andrew Fawcett Jan 30 '13 at 15:39
add comment

  • The PageReference topic in the Visualforce Developers guide covers Page from an Apex Controller perspective.

    Refers to a PageReference for a Visualforce page that has already been saved in your organization. By referring to a page in this way, the platform recognizes that this controller or controller extension is dependent on the existence of the specified page and will prevent the page from being deleted while the controller or extension exists.

  • It's sister $Page feature for use in Visualforce page perspective is also described here.
Best Practice. In your case Page.success points to you having a page named 'succcess' in your org. If you go to Setup > Develop > Pages you will see Visualforce pages listed with Labels and Names. Using this convention is good practice as the platform enforces referential integretity. Meaning if you attempt to delete the page it will stop you and inform you which parts of your code reference it. There are also benefits in respect to avoiding namespace issues when packaging and deploying your solution to this approach.

share|improve this answer
    
Yes indeed it is. If you go to Setup > Develop > Pages you will see Visualforce pages listed with Labels and Names. Using this convention is good practice as the platform enforces referential integretity. Meaning if you attempt to delete the page it will stop you and inform you which parts of your code reference it. There are also benefits in respect to avoiding namespace issues when packaging and deploying your solution to this approach. –  Andrew Fawcett Jan 30 '13 at 15:43
add comment

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

Please refer first point on instantiating .

Page.success means a page with page name "success".Its just a page name which you previously created

share|improve this answer
add comment

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.