-1

I would like to set a return URL after pressing the save commandButton on a new record page. How can I do this?

Code:

  <apex:commandButton value="Submit" action="{!save}" styleClass="btn btn-default" rerender="error,styledError,unstyledError"/> 

EDIT: I would like it redirect to my own custom detail page, which means I must also pass the ID of the record as a paramater

9
  • use PageReference – Yanki Twizzy Oct 6 '14 at 16:02
  • Hi Imran. Do you mean that you have a VF page with the standard controller, and after you press "Save" (which calls the standardcontroller Save method) you want to return to your own URL? How do you get to the VF page in the first place? Is it from a button or link or something? – Dominic Oct 6 '14 at 16:44
  • @Dominic Yes thats exactly what I want. The user will get inital visualforce form via a link from my force.com site. – Deployment Failure Oct 7 '14 at 9:43
  • The answer given by @JennyB is good then. You set &saveURL=/apex/mynextpage on the link that leads to your vf page. Then when the user presses "Save" they go to /apex/mynextpage – Dominic Oct 7 '14 at 9:50
  • @Dominic I have tried adding this to initial new record page url, but when pressing save I am still redirected to the normal detail page for the record. – Deployment Failure Oct 7 '14 at 10:02
1

If you have control over the button/link that is calling the edit page, you can set the saveURL/retURL parameter to control where the page returns to after the "Save" button is clicked. If the page is being called from the standard page, then you could create a custom button and set the parameter in the URL that way. Examples shown here.

0
public PageReference save() {
    // Add the account to the database. 
    insert account;
    // Send the user to the detail page for the new account.
   // You can set your return url here
    PageReference acctPage = new ApexPages.StandardController(account).view();
    acctPage.setRedirect(true);
    return acctPage;
}
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.