Off of this question, I attempted to write code to upload a file to the Files tab in lightning exeperience. Here is the code I used from the salesforce guide:

01<!-- Upload a file and put it in your personal documents folder-->
03<!-- Page: -->
04 <apex:page standardController="Document" extensions="documentExt">
05    <apex:messages />
06    <apex:form id="theForm">
07      <apex:pageBlock>
08          <apex:pageBlockSection>
09        <apex:inputFile value="{!document.body}" filename="{!document.name}"/>
10            <apex:commandButton value="Save" action="{!save}"/>
11          </apex:pageBlockSection>
12       </apex:pageBlock>
13    </apex:form>
16  /*** Controller ***/
17 public class documentExt {
18    public documentExt(ApexPages.StandardController controller) {
19        Document d = (Document) controller.getRecord();
20    d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
21    }                
22 }

It works perfectly....but only on the original salesforce page.

enter image description here

The Files tab on the lightning page looks like this:

enter image description here

There are numerous things I have tried to install or read about on the guide, on github, and on the salesforce forum but none of them seem to properly place the files in the Files tab of lightning.

What functionality could I add to apex to simply upload the files, content and all, to the Files tab in Lightning?

1 Answer 1


You are inserting record into document object and Document object is different than files object in Lightning Experience .

Files represent Content Version Object.Try creating a content version record

public class contentController {

public contentController() {
    file = new ContentVersion();

  public ContentVersion file { get; set; }

  public PageReference go() {
    insert file;
    return new PageReference('/' + file.id);

The Visualforce page is as below

<apex:page controller="contentController">
  <apex:form >
   <apex:inputFile value="{!file.versionData}" fileName="{!file.pathOnClient}" />
    <apex:commandbutton action="{!go}" value="go"/>

Here is a neat blog on the same .

  • For others that will see this answer, the code does not work as written, but the code in the blog link does.
    – isakbob
    Commented Jan 6, 2018 at 3:04
  • @BenjaminSarkis I just changed the code to mirror the blog .Thanks Commented Jan 7, 2018 at 5:46

You must log in to answer this question.

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