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
Mayank Srivastava (Salesforce fan)Mayank Srivastava (Salesforce fan) 

Is there a way to move a file automatically from Contents to Documents?

 

Is there a way to automate the transfer of a file from Contents to Documents on saleforce? I badly need to do this and would appreciate any sort of help on this.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul_sgRahul_sg

hi friend,

 

You need to do some mappings in your code but you can do something like this:

 

 

Document doc = new Document (Name=GIVE_NAME_HERE, FolderId=GIVE_FOLDER_ID, Body= [Select c.VersionData, c.Title, c.Id, c.ContentDocumentId From ContentVersion c where c.ContentDocumentId =GIVE_ID_HERE].VersionData );


insert doc;

 

see if this helps.

All Answers

Rahul_sgRahul_sg

hi friend,

 

You need to do some mappings in your code but you can do something like this:

 

 

Document doc = new Document (Name=GIVE_NAME_HERE, FolderId=GIVE_FOLDER_ID, Body= [Select c.VersionData, c.Title, c.Id, c.ContentDocumentId From ContentVersion c where c.ContentDocumentId =GIVE_ID_HERE].VersionData );


insert doc;

 

see if this helps.

This was selected as the best answer
JitendraJitendra

Soltion provided by Rahul will work. However, if document size is more than 5MB, it will fail. No Workaround for this.