Find your content:

Search form

You are here

Page redirect after export to XL


I have a a VF page that that exports a set of data to excel, the export button correctly redirects to the export page and the file is downloaded.

    public PageReference exportData() {
    PageReference pr = page.ExportImpactAnalogues;
    return pr;

However, once downloaded i want to return to the original screen and its refusing to do so using either:

    public PageReference returnToPrevPage() {

   PageReference redirect = new PageReference('/apex/ImpactAnalogueSelector'); 

    return redirect;


    public PageReference returnToPrevPage() {

   PageReference redirect = Page.ImpactAnalogueSelector; 

    return redirect;

any ideas what im missing??

Cheers Paul

Attribution to: paul

Possible Suggestion/Solution #1

try adding .setRedirect(true) to your pageReference


Attribution to: pjcarly

Possible Suggestion/Solution #2

PageReference redirect = new PageReference('/apex/ImpactAnalogueSelector'); 
return redirect;

Please try the above .

SetRedirect when set to true it helps redirecting

Attribution to: Mohith Shrivastava

Possible Suggestion/Solution #3

I believe this is down to browser behaviour, and I don't think that there is anything you can do about it.

When you generate the Excel format file via a Visualforce page, you set the content type to indicate to the browser that this is actually an Excel file rather than an HTML document. The browser then passes this to the handler for this content type, which in your case is downloading the file.

However, at that point in time you can't make the browser then take further action through HTML/Javascript etc, as the document has been handled via the download plugin which doesn't have a Javascript engine and doesn't know how to process HTML.

The way that I've handled this in the past is to embed the Excel download Visualforce page as an iframe in a wrapper Visualforce page. The wrapper can provide a button or link for the user to return to the previous page, or set a javascript timeout that goes back to the original page after a certain amount of time. I usually favour the former, as if the user is slow to accept the download they may be surprised to be taken elsewhere.

Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content