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
Bhushan.AdhikariBhushan.Adhikari 

Visualforce Error : apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

Hi,

We have a vf page form that has an inputfile tag for uploading image, along with that on the form we have a commandlink that call a javascript method that calles the controller save method and onComplete of this we call a controller method that does a webservice callout. 

So when i click on the command link i get a error saving apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

after reading certain posts i tried putting the commandlink and actionFunctions in actionRegion tag.. and now the above error has gone, but I get a new error saying "You have uncommitted work pending. Please commit or rollback before calling out" 

below is my vf code snippet
<apex:page>
 <apex:form>
<label>Profile Picture (Dimensions 324 x 219 pixels)<span>*</span></label>
<apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>
<apex:commandLink styleClass="social" onclick="SaveRecord_JS();return false;"/>
<apex:actionFunction action="{!save}" name="SaveRecord_JS" oncomplete="CallWebService_JS();"/> 
<apex:actionFunction action="{!authorize}" name="CallWebService_JS"/>
</apex:form>
</apex:page>

if i used above code i get 'apex:inputFile can not be used in conjunction..' error 
and if i put commant link and actionfunction under  <apex:actionregion> tag.. i get callout exception.

Any idea how to overcome this both errors?

Regards,
Bhushan 

Best Answer chosen by Bhushan.Adhikari
Ravi NarayananRavi Narayanan

There are 3 ways for solving this problem

1.Put your apex:inputFile in a separate form and other components in separate FORM.
2.Put your apex:inputFile inside action region and other components inside another action Region.
3.make use of rendered attribute.
Create a Command Button -- Upload.  Whenever you click this commandButton display a section with apex:inputfile. and once file is uploaded immediately remove that section from the page.


==============You cannot use Apex:inputFile and components with Rerender attribute in same form=================

Hit like if it solves your problem

All Answers

logontokartiklogontokartik
Hi Bhushan,

Can you do a callout without Saving a record? If not, I would suggest you to do a callout in a future method if possible. Let me know if this doesnt work yet
Bhushan.AdhikariBhushan.Adhikari
Hi Kartik,
Here is my whole scenario.. 

I need save the current information filled in the form before making a callout.. as when i do a callout it will be redirecting to Twitter signin page and after authorization i will be redirected back to my from. so when i am redirected back to my form i need to display all the information that user had entered before clicking on the link. 

Do you think future method will help here?

Regards,
Bhushan 
logontokartiklogontokartik
Hmm. That's an interesting use case, can you do callout first and then ask user to enter info? Maybe add another button for callout? If its not a lot of info you can also pass them as state params on URL which will come back. But to make it short you cannot have a dml and then do a callout for sure..
Bhushan.AdhikariBhushan.Adhikari
Hi Kartik,

Thanks for your suggestion! Yes i know that's why i opted for actionsupport which was working as required before adding inputFile on the form. Unfortunately i cannot pass parameters as there are more than 50 fields on the form to capture user data. I think i need to warn user to save info himself and then do a callout.

Thanks for ur time!

Regards,
Bhushan
Ravi NarayananRavi Narayanan

There are 3 ways for solving this problem

1.Put your apex:inputFile in a separate form and other components in separate FORM.
2.Put your apex:inputFile inside action region and other components inside another action Region.
3.make use of rendered attribute.
Create a Command Button -- Upload.  Whenever you click this commandButton display a section with apex:inputfile. and once file is uploaded immediately remove that section from the page.


==============You cannot use Apex:inputFile and components with Rerender attribute in same form=================

Hit like if it solves your problem

This was selected as the best answer
Bhushan.AdhikariBhushan.Adhikari
Hi Ravi,

I tried your 3rd suggestion and it does seems to work!
Thanks!!

Regards,
Bhushan
logontokartiklogontokartik
Hi, Did you know i uploaded my latest pictures on my Google Drive page today?Well, I’ve uploaded it again on my Google Drive click here to view them and tell me what you think. Regards Thanks and Regards, Kartik Viswanadha @logontokartik 972.365.7780 about.me/logontokartik * - Live as if you were to die tomorrow. Learn as if you were to live forever*