You need to sign in to do that
Don't have an account?
devNut!
apex:inputFile - throws "Insert failed" on second file being uploaded
I am experimenting with the "<apex:inputFile>" tag trying to create a page where the user can upload one file at a time. The first file upload works but the second one throws the exception:
Here is the scenario:
1) load file upload page
2) select and upload file
3) user is re-directed to the file upload page
4) select and upload file
5) exception: Insert failed. First exception on row 0 with id 01530000000henEAAQ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
It's like the context is not being reset when the page is refreshed (see return from doSave() below)
Any input is appreciated.
VF Page
Controller Extension
Message Edited by devNut! on 11-17-2008 12:35 PM
Here is the scenario:
1) load file upload page
2) select and upload file
3) user is re-directed to the file upload page
4) select and upload file
5) exception: Insert failed. First exception on row 0 with id 01530000000henEAAQ; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
It's like the context is not being reset when the page is refreshed (see return from doSave() below)
Any input is appreciated.
VF Page
Code:
<apex:page standardController="Document" extensions="TestFileUploadControllerExtension" showHeader="false" sidebar="false"> <apex:messages /> <apex:form id="theForm"> <apex:pageBlock > <apex:pageBlockSection > <apex:inputFile value="{!document.body}" filename="{!document.name}"/> <apex:commandButton value="save" action="{!doSave}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Code:
public class TestFileUploadControllerExtension {
ApexPages.StandardController controller;
public TestFileUploadControllerExtension(ApexPages.StandardController c)
{
System.debug('@@@@@@@@ TestFileUploadControllerExtension');
this.controller = c;
}
public PageReference doSave()
{
System.debug('@@@@@@@@ doSave');
Document d = (Document) controller.getRecord();
System.debug('@@@@@@@@ document name: '+d.name);
d.folderid = UserInfo.getUserId(); //store in Personal Documents
System.debug('@@@@@@@@ document folder id: '+d.folderid);
insert d;
System.debug('@@@@@@@@ document object id: '+d.id);
System.debug('@@@@@@@@ redirect');
PageReference page = new PageReference('/apex/TestFileUpload');
return page;
}
}
Message Edited by devNut! on 11-17-2008 12:35 PM
Hmm, I was hoping that would cause the controller to re-instantiate (reload) but I guess it doesn't. (it does)
I haven't played with the inputFile component much but if I have time I'll try to dig deeper a little. I would think it is possible to upload multiple files without having to reload the entire page.
Message Edited by TehNrd on 11-18-2008 09:10 AM
It seems that reloading of the page is the only way to clear the underlying document variable in the standard controller.
Once an upload happens the following line
returns the uploaded document i.e. the ID field is populated.
I thought you said it didn't work.
hi,
How to creat a s- control for upload document file