Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is there any way we can delete Latest Version from ContentDocument?

I have tried deleting ContentVersion, but DML Operation Delete is not allowed on it.

I have tried deleting ContentDocument, but it deletes ALL versions and the document itself.

share|improve this question
add comment

1 Answer

Yes, all the version will be deleted, check the doc here, ContentDocument

'When you delete a document, all versions of that document are deleted, including ratings, comments, and tags.'

Yeah, there is no standard way to do this. But you can copy the latest version to a new file, and delete all the old version, like this,

ContentVersion oldCV = [Select Id, VersionData, PathOnClient, ContentUrl, Title, PublishStatus, Origin from ContentVersion Order By CreatedDate Desc Limit 1];

ContentVersion newCV = new ContentVersion();
newCV.Title = oldCV.Title;
newCV.PathOnClient = oldCV.PathOnClient;
newCV.ContentUrl = oldCV.ContentUrl;
newCV.VersionData = oldCV.VersionData;
newCV.Origin = 'H';
insert newCV;
share|improve this answer
    
so there is no way I can delete only the Latest version and restore previous version? –  Varun Chaddha Jun 15 '13 at 8:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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