I noticed in Winter '16 it looks like there is a new "Files" tab available. I added this as a related list to one of my page layouts on a custom object.

Can someone provide code showing how to insert an attachment via apex to this new files related list or point me to somewhere online that illustrates how to leverage this relatively new functionality?

I know how to create an attachment via apex, but I believe this is more linked to chatter and it's not clear how to insert a new record programmatically.

  • Pretty sure there is zero relation between files and attachments.
    – Adrian Larson
    Jun 17 '16 at 20:41
  • 2
    I'm not quite sure how to interpret your answer. I can write apex to add a new record to the "Notes and Attachments" related list, but this seems different so I'm wondering how can I do the same, but have my file appear under the "Files" related list. Not sure if that helps clarify my initial question or not. Jun 17 '16 at 20:48
  • It is soo annoying when answers are mark as duplicate and hey dont add the "duplicate question", I have been searching for hours for this, did you ever found a solution, the only thing i find online is using a "converter", but I need to generate a file from an API response
    – manza
    Sep 17 '18 at 1:46

You need to use ContentVersion object to insert file.

Please refer this post: upload files

Not the answer you're looking for? Browse other questions tagged or ask your own question.