Suppose I am redirected from page 1 to page 2 due to some action performed on VF page . I am looking for a way to use a hyper link in page 2 clicking on that will redirect me back to page 1 . Anyone can help me out with some hints!! thanks.
For standard pages Salesforce implemented a nice pattern: when redirecting the source page passes parameter
retURL that tells the target page where to return. For example when you choose to Edit a contact from the account layout, Salesforce takes you to
https://<instance>.salesforce.com/<Contact ID>/e?retURL=%2F<Account ID>
and redirects back to the account after saving changes or canceling.
retURL param can be easily accessed from both APEX:
BTW when getting
retURL in apex you should enclose ist in a try catch block. Becuase sometimes a user can directly go to that page in which case there will be no
retURL. If an exceptio0n occurs then it means that no
retURL parameter is present then you can just redirect to page you want by creating a custom
Of course there are other options, for example playing with HTTP Referer.