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
NARESH DEVARASETTINARESH DEVARASETTI 

ContentVersion is getting save in notes and attachments not in files when insert from visualforce page

Hi,

I am facing an issue with the contentVersion. When I am inserting the contentVersion record from visualforce page action to attach the another VF page as pdf. Its getting attached in notes & attachment related list but I want to add that in files related list.
Please help here

User-added imageUser-added image

SwethaSwetha (Salesforce Developers) 
HI Naresh,
Your ask seems similar to https://salesforce.stackexchange.com/questions/238009/upload-attachments-to-files-related-list-using-apex

"Like the option says it attaches files only when its uploaded from related list(Only from the standard related list UI). From apex you're supposed to insert a contentDocument, which is a salesforce file but what you're attaching is just an attachment. Salesforce doesn't automatically convert attachment into a file. You need to insert a file explicitly!"

You might want to try the approach of using trigger on Attachment, with a Before and After, to move attachments over to files.
trigger AttachmentSaver on Attachment (after insert, before insert) {
    if (Trigger.isInsert) {
        if (Trigger.isBefore) {

            for (Attachment att : Trigger.new) {

                ContentVersion cv = new ContentVersion();
                cv.PathOnClient = att.Name;
                cv.Title = att.Name;
                cv.Description = att.Name;
                cv.VersionData = att.body;
                cv.FirstPublishLocationId = att.ParentId;
                insert cv;

                att.description = att.Name + '-relocatedToFiles';

            }
        }

        if (Trigger.isAfter) {
            delete [select id from Attachment WHERE id in :Trigger.new AND description like '%-relocatedToFiles'];
        }
    }   
}

Related:https://salesforce.stackexchange.com/questions/122301/migrate-attachments-to-salesforce-files

https://douglascayers.com/2015/10/10/salesforce-convert-attachments-to-chatter-files/

If this information helps, please mark the answer as best. Thank you​​​​​​​
NARESH DEVARASETTINARESH DEVARASETTI
Thank you for your reply. 
We are aleady using contentVersion and contentDocumentLink to save the file but instead of getting saved in files it is getting saved in both notes & attachments and files.
Is there any way to get rid off not saving in notes & attachments?
Brad Nordling 9Brad Nordling 9
Naresh, did you ever get this resolved?  I experience the same thing - when I insert a ContentVersion, it saves the file in "files" and also in "Notes and Attachments".  I only want it in one place.  Preferably Files.