2

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() {
    system.debug(Ids);
    PageReference pr = page.ExportImpactAnalogues;
    pr.setredirect(true);
    pr.getParameters().put('exportIds',Ids);
    return pr;
}

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

    public PageReference returnToPrevPage() {

    system.debug('REDIRECTING');
   PageReference redirect = new PageReference('/apex/ImpactAnalogueSelector'); 

    return redirect;
}

or

    public PageReference returnToPrevPage() {

    system.debug('REDIRECTING');
   PageReference redirect = Page.ImpactAnalogueSelector; 

    return redirect;
}

any ideas what im missing??

Cheers Paul

3 Answers 3

1

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.

0

try adding .setRedirect(true) to your pageReference

See: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

1
  • unfortunately, thats not made any difference. I gather this only has any inffluence if the 2 pages use the same controller, which they dont. Maybe thats the answer, use the same controller...?
    – paul
    Dec 17, 2012 at 11:03
0
PageReference redirect = new PageReference('/apex/ImpactAnalogueSelector'); 
redirect.setRedirect(true);
return redirect;

Please try the above .

SetRedirect when set to true it helps redirecting

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .