I'm building a Visualforce page that let's the user upload some images, they can add as many images as they want, when they click on the "add new" button, a new record is inserted and one of the record fields is the path where it'll be uploaded to.
Here's the button and the action related:
<apex:form >
<apex:actionFunction action="{!createFile}" name="createRecord" reRender="none"/>
</apex:form>
<input class="btn" type="button" id="add-btn" value="{!$Label.Add_New}" onclick="createRecord()" />
and the createRecord method:
public String fileName {get;set;}
public void createFile(){
String folder = ApexPages.currentPage().getParameters().get('orgId');
try {
Custom_Object__c file = new Custom_Object__c();
//Some fields get assigned
insert file;
Transient Custom_Object__c tmpFile = [SELECT Path__c FROM Custom_Object__c WHERE Id = :file.Id limit 1];
fileName = folder + tmpFile.Path__c + ‘.jpg’;
System.debug(fileName);
} catch (DMLException e){
System.debug('DML EXCEPTION: ' + e);
} catch (QueryException e) {
System.debug('Query EXCEPTION: ' + e);
}
}
Then I'm getting the fileName
value in order to upload the file.
<form
action="https://someurl.com/"
method="post" enctype="multipart/form-data" >
<input type="hidden" name="key" value="{!fileName}" />
<input type="file" size="255" name="file" />
<input class="btn" type="submit" value="{!$Label.Upload}"/>
</form>
The problem is that when I called the createRecord
function with the reRender="none"
to prevent it from refresh the entire page, the {!fileName}
call doesn't get the just updated value. When I remove the reRender="none"
it gets the new value just fine, I need it to get the new value without refreshing the entire page, how can I do this?