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
SalesRedSalesRed 

OnComplete of ActionFunction When PageReference Returned?

Hello,  

I have a visualforce page which has an apexActionFunciton which returns a PageReference which initiates a file download (the URL returned in the pagereference is a signed URL from an external file system).  What I would ideally like to do is to close my visualforce page once the ActionFunction completes however the onComplete does not execute in the apex:actionFunction  (presumably because the PageReference has caused the execution to leave the Visualforce page).
All I wish to do is to close the Visualforce page on completing the actionFunction,

Does anyone know of the best way this can be achieved?

Thanks in advance for any suggestions.
ShashankShashank (Salesforce Developers) 
There's something called "onbeforedomupdate". Please try using it instead of oncomplete and check if this resolves your issue.
shiv@SFDCshiv@SFDC
oncomplete event is there on action function.

<actionFunction onComplete="window.close()"................>
SalesRedSalesRed
Hi, I;ve tried both onComplete and onbeforedomupdate but neither are processed.  I guess it's because the context of the page is lost with the returned PageReference?
shiv@SFDCshiv@SFDC
Yes. It's right. But why you want user to redirect to a new winod and close window on same time ?
SalesRedSalesRed
Hi.  The reason I want to do it is as follows.
- I use my Visualforce page to generate a signed file url for downloading files.
- The only reason I open the VF page is for the controller to process this.
- On the Signed URL being created the URL relates to a file which I want to download
- I don't need the VF page otherwise.
- If I could do this without having to open a VF page it would be best.

Thanks again for any suggestions!
Samiullah saudagarSamiullah saudagar
Thanks for the question.