• Hassan CASSIM
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I'm not developer unfortunately , thanks a lot if you can help.
Here is the code of the trigger that actually working, just need the test class :

trigger DeleteContentDocumentLink on Case (Before Update,After Update, Before Delete) {
 public Set<Id> CaseSetId = new Set<Id>();
 List<Case> csToUpdt = new List<Case>();

 if(Trigger.isAfter && Trigger.isUpdate){
    for(Case cs:Trigger.New){
        if(cs.TECH_DeleteFiles__c== True){
            CaseSetId.add(cs.Id);
        }
    }
    If(CaseSetId.size()>0){
        List<ContentDocumentLink> casAttmtList = [SELECT ContentDocumentId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case WHERE TECH_DeleteFiles__c = TRUE ) and LinkedEntity.Type='Case'];
        Integer count=0;
        for (ContentDocumentLink x : casAttmtList) {    
            List<ContentDocument> casFiles = [SELECT Title FROM ContentDocument WHERE Id = :casAttmtList[count].ContentDocumentId ];
            delete casFiles;
            count++;
            }
    }
}}

Thanks a lot
I'm not developer unfortunately , thanks a lot if you can help.
Here is the code of the trigger that actually working, just need the test class :

trigger DeleteContentDocumentLink on Case (Before Update,After Update, Before Delete) {
 public Set<Id> CaseSetId = new Set<Id>();
 List<Case> csToUpdt = new List<Case>();

 if(Trigger.isAfter && Trigger.isUpdate){
    for(Case cs:Trigger.New){
        if(cs.TECH_DeleteFiles__c== True){
            CaseSetId.add(cs.Id);
        }
    }
    If(CaseSetId.size()>0){
        List<ContentDocumentLink> casAttmtList = [SELECT ContentDocumentId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case WHERE TECH_DeleteFiles__c = TRUE ) and LinkedEntity.Type='Case'];
        Integer count=0;
        for (ContentDocumentLink x : casAttmtList) {    
            List<ContentDocument> casFiles = [SELECT Title FROM ContentDocument WHERE Id = :casAttmtList[count].ContentDocumentId ];
            delete casFiles;
            count++;
            }
    }
}}

Thanks a lot