When using apex:inputFile to attach docs to an object,

<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>

I need to click a second button after selecting my file to save it,

<apex:commandButton action="{!upload}" value="Save"/>

Is there any way to automatically call the Save button from the inputFile? Or can the inputFile call my upload method?

I want to select a file and upload it in one click, is that possible?

1 Answer 1


I believe my answer to your other question related to "custom apex:inputFile icon/image" should be of help here as well. https://stackoverflow.com/questions/23110868/add-custom-apexinputfile-icon-image/23594092#23594092

after step 4 i.e. "trigger the click() of standard "choose file" when custom element is clicked" you just need to add the javascript code that mimics the click of the save button.

Hope that helps.

You must log in to answer this question.

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