Notes
public class DocumentUtility {
public static void DeleteDocumentsFromAccount(){
List<ContentDocumentLink> contentDocumentToDelete = [SELECT ID,ContentDocumentId
FROM ContentDocumentLink
WHERE LinkedEntityId in (SELECT Id FROM Account)];
List<String> contentIdsToDelete = new List<String>();
for (ContentDocumentLink docLink : contentDocumentToDelete) {
contentIdsToDelete.add(docLink.ContentDocumentId);
}
List<ContentDocument> cdToDelete = [SELECT ID FROM ContentDocument WHERE ID in :contentIdsToDelete];
delete cdToDelete;
}
public static void DeleteDocumentsFromAccountB(Integer QueryLimit){
List<ContentDocumentLink> contentDocumentToDelete = [SELECT ID,ContentDocumentId
FROM ContentDocumentLink
WHERE LinkedEntityId in (SELECT Id FROM Account where CreatedDate < LAST_N_DAYS:1) LIMIT : QueryLimit];
List<String> contentIdsToDelete = new List<String>();
for (ContentDocumentLink docLink : contentDocumentToDelete) {
contentIdsToDelete.add(docLink.ContentDocumentId);
}
List<ContentDocument> cdToDelete = [SELECT ID FROM ContentDocument WHERE ID in :contentIdsToDelete];
delete cdToDelete;
}
}