Delete Content documents from Library

Id LinkedEntityId = [SELECT Id FROM ContentWorkSpace WHERE Name = 'Asset Library' LIMIT 1].Id;
List<ContentDocumentLink> ContentDocumentLinkList =[SELECT ContentDocumentId, LinkedEntity.Name, LinkedEntityId, LinkedEntity.Type FROM ContentDocumentLink WHERE ContentDocumentId =:LinkedEntityId];
List<Id> DocIdList = new List<Id>();
for(ContentDocumentLink cdLink: ContentDocumentLinkList){
DocIdList.add(cdLink.ContentDocumentId);
}
List<ContentDocument> ConDocList =[SELECT Id, CreatedBy.Name, ContentSize, ParentId FROM ContentDocument WHERE Id IN: DocIdList];
delete ConDocList;
view raw deleteFiles hosted with ❤ by GitHub