+ Start a Discussion
Romeo MirzacRomeo Mirzac 

Redirecting back to Original page

Sorry for this simplistic question, but I have a custom button on 2 different pages which calls the same Visualforce page.  How can I redirect the user back to the correct page when they hit "back" on my custom page?

NOTE:  One of the pages with the button that calls the VF page is the standard list page...

Thanks
Best Answer chosen by Romeo Mirzac
shail@trekkingshail@trekking
You can do one simple approach:

1. On click of buttons - pass current page URL (window.location) as a parameter to VF page.

For example on click of button 1, URL would be - https://ap1.salesforce.com/apex/somePage?retUrl=/001xxxxx...
And on click of button 2, URL would be - https://ap1.salesforce.com/apex/somePage?retUrl=/003xxxxx...

2. In your VF controller, get this retUrl parameter and bind it with your back button.

A more generic approach would be to use document referrer or document history in Javascript.

All Answers

Jen BennettJen Bennett
Take a look at this guide, it should help you find what you are looking for:
http://www.developerforce.com/guides/Visualforce_in_Practice.pdf
shail@trekkingshail@trekking
You can do one simple approach:

1. On click of buttons - pass current page URL (window.location) as a parameter to VF page.

For example on click of button 1, URL would be - https://ap1.salesforce.com/apex/somePage?retUrl=/001xxxxx...
And on click of button 2, URL would be - https://ap1.salesforce.com/apex/somePage?retUrl=/003xxxxx...

2. In your VF controller, get this retUrl parameter and bind it with your back button.

A more generic approach would be to use document referrer or document history in Javascript.
This was selected as the best answer
Romeo MirzacRomeo Mirzac
Excellent, thank you!