+ Start a Discussion

Help with retURL behavior: after -New- button and save, goes to list not detail view, why?

Hey community!
Easy question.
1. I have a visualforce page that is an edit page
2. I override both the edit and new standard buttons so that they go to this page.
Use Case
a) I am in the list view to show many records of my object
b) I click on the "New" standard button to create a new record, it goes to this page:
c) I add data and click save.
d) PROBLEM: After the save it takes me to the list view, not the newly created records detail view.
I can see by the URL that the retURL will throw me back to the list view, not the detail view, but why this behavior? How do I override it if possible or account for it?
Thanks and do let me know if you need more clarity.
Appreciate in advance!

Message Edited by bev90210 on 10-09-2008 06:49 PM

Message Edited by bev90210 on 10-09-2008 06:50 PM

In your save method of your VP page controller redirect the user to the detail page of your object.

public PageReference save()
  Your Code ....

  PageReference detailPage = new PageReference('/'+ myNewObject.id);

  return detailPage;


It's always preferable to avoid string-based navigation.  In formulas we have the URLFOR() function and $Action global and in Visualforce / Apex you can utilize the ApexPages.StandardController (and now also ApexPages.StandardSetController) for navigation without worrying about salesforce.com changing URLs or request parameters.

For this example the following code will force the navigation as you have specified:

public class newAccountExt {

    ApexPages.StandardController con;
    public newAccountExt(ApexPages.StandardController controller) {
        con = controller;
    public PageReference save() {
        return con.view();



<apex:page standardController="Account" extensions="newAccountExt">
<apex:form >
<apex:inputField value="{!account.name}"/>
<apex:commandButton value="create" action="{!save}"/>


Thanks for the assistance guys.
But I'm trying to avoid using Apex classes, any way to do this without a custom extension?
Not today. Not safely anyway.
I'm trying to do something similar, but I'm having bad luck -- I've got a custom object that I want to go to the standard "new" page when it is a specific record type. 

However, if I have the controller extension call the standard controller's edit page under those circumstances:

             return controller.edit();

I get a message that says

       You cannot call edit() on a null object

Any suggestions?