function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

apex trigger - delete File - ContentDocumentLink

Hi Stars,

I am trying to implement an apex trigger the detects if a File is deleted (so as to, in another apex class, verify if the Parent Object Case has any remaining children Files attached to it or not and consequently edit a boolean field on Case).

I got the solution to work smoothly when the File is added (trigger.isInsert) but that trigger does not work when having to spot/detect when a file is deleted.

I am doing manual tests with Classic.

Salesforce's article ( states that, for a trigger to be able to detect when a File is deleted from Classic, the trigger must be on the object ContentDocumentLink (not ContentDocument).

However,  in spite of the above statement on Salesforce's article, when manually deleting a File (attached to a Case) from the Service Console, the trigger on ContentDocumentLink is not being triggered (I can see that with a System.debut method).

Here is my code:
trigger ContentDocumentLinkTrigger on ContentDocumentLink (after insert, after delete) {
    System.debug('FROM ContentDocumentLinkTrigger: Entered the trigger');
    Set<Id> ContentDocumentLinkIds = new Set<Id>();
    Set<Id> parentCasesIds = new Set<Id>();
    if(trigger.isInsert || trigger.isUndelete){
        System.debug('FROM ContentDocumentLinkTrigger - triggerNew if isINSERT or isUNDELETE');
            System.debug('FROM ContentDocumentLinkTrigger - triggerNew if isAFTER');
            for(ContentDocumentLink cdl :{
    //---> DELETING FILE
        System.debug('FROM ContentDocumentTrigger - Entered isDelete');
            System.debug('FROM ContentDocumentTrigger - Entered isAfter');
Could you possibly help me find out WHY is this trigger not triggering when deleting a File (associated to a Parent Case) from the Service Console in Classic?

Thank you very much.