You need to sign in to do that
Don't have an account?
Thomas Reinman 16
VersionData Missing when trying to Insert ContentVersion
I'm re-using some code that I've used in the past to upload and insert a File into Salesforce from a Visualforce page.
Apex:
Visualforce:
VersionData should be populated when the file gets uploaded, but for some reason I'm still getting an error message:
Thanks for any support
Apex:
// rfpio is the variable associated to a custom sObject that was inserted previously public PageReference addFile(){ try{ ContentVersion conver = new ContentVersion(); conver.ContentLocation = 'S'; conver.PathOnClient = System.now().format('MM-dd-YY') + ' ' + title; conver.Title = title; conver.VersionData = VersionData; insert conver; System.debug(conver); Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conver.Id].ContentDocumentId; // Create a ContentDocumentLink to the case ContentDocumentLink cDe = new ContentDocumentLink(); cDe.ContentDocumentId = conDoc; cDe.LinkedEntityId = rfpio.Id; cDe.ShareType = 'V'; cDe.Visibility = 'AllUsers'; insert cDe; System.debug(cDe); } catch(System.DMLException e){ System.debug(e); return null; } return new PageReference('/'+rfpio.Id); }
Visualforce:
// Here is the part of the page where the user can upload a blob <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Upload" action="{!addFile}"/> </apex:pageBlockButtons> <apex:inputFile value="{VersionData}" fileName="{!title}" required="true"></apex:inputFile>
VersionData should be populated when the file gets uploaded, but for some reason I'm still getting an error message:
Thanks for any support
Thomas Reinman 16
*** Sorry important detail, 'VersionData' was previously defined as 'public Blob VersionData {get; set;}' at the top of the class
Thomas Reinman 16
Update - I was missing a ! in the {VersionData} on the VF page. -_-