Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

try adding .setRedirect(true) to your pageReference

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

share|improve this answer
    
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 '12 at 11:03
PageReference redirect = new PageReference('/apex/ImpactAnalogueSelector'); 
redirect.setRedirect(true);
return redirect;

Please try the above .

SetRedirect when set to true it helps redirecting

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.