You need to sign in to do that
Don't have an account?
David Roberts 4
how to add a document version
I can create a file using:
but how do I overwrite it (add a new version) so I don't get multiple 'debuglog.txt' files?
String strDebug = 'some debug information \n'; //ContentDocument //SELECT title, LatestPublishedVersionId FROM ContentDocument where title = 'debuglog.txt' ContentVersion file = new ContentVersion( title = 'debuglog.txt', versionData = Blob.valueOf( strDebug ), pathOnClient = '/debuglog.txt' ); insert file;
but how do I overwrite it (add a new version) so I don't get multiple 'debuglog.txt' files?
Thanks for your suggestion.
It gave me clues to find the solution:
I first queried the CurrentVersion for a file with the title 'Debug Log' retrieveing the ContentDocumentId (parent container).
I then create a new version telling it about the parent ContentDocumentId.
(I should probably cater for no parent found...).
Regards,
Dave.
All Answers
Select the object on which the file is present and click on that file. It will open the location of the file.
1. On the left side, you'll see an option to 'upload new version' or if you are using the lightning version select this option from the right side drop-down button.
2. Select that option and select the new file that you want to replace.
3. You're done. Now the old file is overwritten.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Use this code to create a new version of an existing file:
Here the DocumentId is the ContentDocumentId of the document of which you want to change the version.
All the other attributes such as base64Data and fileType etc. can be changed.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Thanks for your suggestion.
It gave me clues to find the solution:
I first queried the CurrentVersion for a file with the title 'Debug Log' retrieveing the ContentDocumentId (parent container).
I then create a new version telling it about the parent ContentDocumentId.
(I should probably cater for no parent found...).
Regards,
Dave.