I created a visualforce page with a button to download a document, this work fine, but after download the document I want to delete the file without to click in another button, this is the code I am using:
<apex:page standardController="npe03__Recurring_Donation__c" extensions="ReporteCompromisosExportacionController" action="{!getFile}" tabStyle="Reporte_Compromisos__tab">
<apex:form >
<apex:actionFunction name="download" action="{!downloadFile}"/>
<apex:actionFunction name="deletef" action="{!deleteFile}" rerender="name"/>
<apex:pageBlock id="page">
<apex:pageBlockSection columns="1" title="Descargar Archivo de Cobranza" collapsible="false">
<apex:pageBlockSectionItem >
<apex:image url="{!$Resource.excelIcon}" width="30" height="30"/>
<apex:outputText id="name" value="Archivo {!fileName}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:CommandButton value="Descargar Archivo" action="{!downloadFile}" oncomplete="deletef();" rerender="name"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Extension
public void getFile(){
String idDocument = Apexpages.currentPage().getParameters().get('doc');
List<Document> docs = [SELECT Name FROM Document WHERE Id =: idDocument];
if(docs.size()>0){
fileName = docs.get(0).Name;
}
}
public String downloadFile(){
String idDocument = Apexpages.currentPage().getParameters().get('doc');
String URL = '/servlet/servlet.FileDownload?file=' + idDocument;
return URL;
}
public void deleteFile(){
String idDocument = Apexpages.currentPage().getParameters().get('doc');
Document d = new Document();
d.Id = idDocument;
delete d;
}
}
The oncomple method doesn't work, can some one help me please?