function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bev90210bev90210 

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:
https://na2.salesforce.com/a05/e?retURL=%2Fa05%2Fo
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
Sam.arjSam.arj

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


Code:
public PageReference save()
{
  .....
  Your Code ....
  ....

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

  return detailPage;
}
  
}

 


mtbclimbermtbclimber
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:

Code:
public class newAccountExt {

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

}

PAGE:

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

 

bev90210bev90210
Thanks for the assistance guys.
 
But I'm trying to avoid using Apex classes, any way to do this without a custom extension?
mtbclimbermtbclimber
Not today. Not safely anyway.
michaellatideasmichaellatideas
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?