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
HarryHHHarryHH 

How to return to previous page

Hello I have a Visualforce page with a standardcontroller and a controller extension. In this there is a pagereference method in which I save a new order-record. I now want to redirect the user to the previous page. How can I do that. I tried it with the following:

 

public string retPage = ApexPages.currentPage().getParameters().get('retURL');

page.retPage;

 

did not work. The same with

 

return retPage;

 

Where is the fault?

 

Thanks

Harry

Ryan-GuestRyan-Guest

Can you just return null;

 

I believe that bounces you back to the previous page.

HarryHHHarryHH

No, if I just return null that leaves me on the detail page of the inserted record.

 

Thanks

Harry

gv007gv007

look apex developer guide there is lot of example is there for page ref.

 

it is simple.

PaqsPaqs

Hi HarryHH,

 

You were close, the problem is that the 'retUrl' parameter is just the id, you need to provide the full page reference as such depending on the following two use cases:

 

If you came from a page that had a specific record id selected (aka the url has a ?id=<id> parameter, then your retPage will be:

 

PageReference retPage = new PageReference('/'+apexPages.CurrentPage().getParameters().get('id')); 

return retPage;

 

Or if you were on a record directly (aka the url was <salesforceinstanceurl>/<id of object>) then the retPage will be:

 

PageReference retPage = new PageReference('/'+ ApexPages.currentPage().getParameters().get('retURL'));

 

Hope this helps