[SalesForce] BeforeDelete Trigger on ContentDocumentLink object not firing

I have a trigger on ContentDocumentLink object. I have use case to show total number of Files and number of notes attached if the link was between Events and Content using Salesforce Content. And, offcourse, similar thing that needs to be done when a content is removed.

Code

trigger ContentDocumentLinkTrg on ContentDocumentLink (after insert, before delete)  
{
    //Check if customization is not enable through custom settings
    if(!CustomSettingsUtil.IsCustomizationEnabled())
    {
        return;
    }
    String BeforeOrAfter = (Trigger.isBefore ? 'Before' : 'After');
    String TriggerType = ''
        + (Trigger.isDelete ? 'Delete' : '')
        + (Trigger.isInsert ? 'Insert' : '');
    system.debug(BeforeOrAfter + ' ' + TriggerType);
    // run TriggerHandler
    new ContentDocumentLinkTriggerHandler().run();

}

Checking the debug log, it is entering the AfterInsert event but not BeforeDelete. I see no restrictions in the SF documentation, can anyone put some light on this, please.

Edit

I'm having this issue on Lightning while on SF-Classic this functionality is working fine.

Best Answer

I know this is quite late response, I totally forgot about this question. Anyhow, just updating this question so that if anyone does encounter such an issue, he/she may find solace.

I'm not sure if this is a bug or by-design, but when you delete a Content link between two objects in Salesforce Lightning, ContentDocumentLink trigger works fine but when a user delete the content in Salesforce Classic from the Files or Notes related list

  • file or note itself gets deleted
  • ContentDocumentLink is also not fired if user deletes the file/note through Chatter

I believed it should, as the File/Note is deleted its link also gets deleted but the trigger never fired. I logged a case with Salesforce but as usual technical I didn't get any helpful response.

So I implemented two more triggers to handle this

  1. a trigger on ContentDocument object to handle deletion of Note/File itself.
  2. a trigger on FeedItem object to handle content deletion from Chatter.
Related Topic