I am reading through the Visualforce developer's guide and found the example of creating a wizard might be wrong. The link is https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm .

In the controller code:

 public PageReference cancel() {
        PageReference opportunityPage = new ApexPages.StandardController(opportunity).view();
        return opportunityPage; 

Although in the previous code:

 public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;

Opportunity is a new instance, it is not inserted into database yet. Hence if we click cancel before save (that's where we should click cancel in real case), it will throw an exception. Am I understanding it correctly?

So my question here is how to make it work? By inserting a random opportunity will make this work, but that's ugly.

1 Answer 1


I'd think so. The ApexPages.StandardController.view() seems to return a PageReference with null as it's URL as demonstrated by:

    (new ApexPages.StandardController(new Opportunity()).view()).getURL()
); //in log as USER_DEBUG [1]|DEBUG|null

So the assertion in the comments:

// This method cancels the wizard, and returns the user to the
// Opportunities tab

seems to be untrue, although the intention of the author is at least clear.

You must log in to answer this question.

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