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 listI 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