Thursday, January 9, 2020

How to Delete all Files from Library using Apex

If you have to delete any library, then first you have to delete all the files present in that library. For this purpose you can run below mentioned simple apex script to delete all files from library.

string LibraryName='Demo Library';
ContentWorkspace ws = [SELECT Id, RootContentFolderId FROM ContentWorkspace WHERE Name = :LibraryName LIMIT 1];
List<ContentDocument> contentDocumentIds = new List<ContentDocument>();
for(ContentDocumentLink con:[select id,LinkedEntityId,ContentDocumentId   from ContentDocumentLink  where LinkedEntityId=:ws.Id]){
    contentDocumentIds.add(new ContentDocument(id=con.ContentDocumentId));
}
system.debug('********contentDocumentIds:'+contentDocumentIds);
system.debug('********contentDocumentIds.size:'+contentDocumentIds.size());
database.delete(contentDocumentIds,false);


Hope this will help!!

7 comments:

  1. They can't depend on traditional file transfer strategies like email, messenger administration and FTP when the files are an excessive number of and excessively enormous and should be sent at the earliest opportunity.transfer files

    ReplyDelete
  2. Twitter Promotion is a great way to have this blog seen but if you have videos you can also buy tiktok views and more !

    ReplyDelete
  3. YouTube Promotion seems a great way to have your videos seen but you can also buy slow instagram likes as well for your photos to receive daily traffic.

    ReplyDelete