[SalesForce] How to delete document in content version

@RemoteAction
public static void DeletePriorties(string Rid)    {   
    ContentVersion sList =[Select id,Title,FileType,GeneratedDate__c,FilelinkedCode__c,ContentUrl,createdby.name
                            FROM ContentVersion 
                            WHERE SourceRequisitionId__c=:Rid];

    ContentVersion file= new ContentVersion();
    file.OwnerId=UserInfo.getUserId();
    file.FileLinkedCode__c=sList.FileLinkedCode__c;
    file.SourceRequisitionId__c=sList.SourceRequisitionId__c;
    file.pathOnClient=sList.pathOnClient;
    file.versionData=sList.versionData;
    file.GeneratedDate__c=sList.GeneratedDate__c;
    insert file;
    delete sList;
}

But I got this error:

 Compile Error: DML operation DELETE not allowed on ContentVersion at line 535 column 9 

I followed this link but i Don't KNOW HOW TO USE THIS QUERY. https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm#sforce_api_objects_contentversion

Best Answer

In the SFDC Objects documentation you referenced, at the top of the page is this line:

create(), describeLayout(), describeSObjects(), query(), 
retrieve(), search(), update(), upsert()

No delete - hence a DML delete on this object is not permitted.

This makes sense because in the user interface, you can't delete a version either, only add a new one

All ContentVersion versions are hung under (as a child) a ContentDocument. The ContentDocument, if deleted, deletes all child ContentVersions

From the SFDC Object reference documentation on ContentDocument:

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