Loading

ContentDocument and ContentDocumentLink trigger behavior in Classic and Lightning

Udgivelsesdato: Jun 26, 2023
Beskrivelse
The following behavior applies to the deletion of a file attached to a record:
  • In Classic, ContentDocument triggers do not fire, as Salesforce only deletes the associated ContentDocumentLink record, not the ContentDocument record.
  • In Lightning Experience, both the ContentDocument and related ContentDocumentLink records are deleted, and by design Salesforce only fires the trigger on ContentDocument, not the trigger on ContentDocumentLink.
Løsning
This is working as designed and can be verified by following below steps:
1. Create two "before delete"  triggers: one on ContentDocument, and the other on ContenDocumentLink objects.
2. Place a "system.debug" statement in each which could be verified in the Debug logs.
3. Now upload 2 files to any Object record under 'Files' related list. Once done, you can observe both the uploaded documents under the 'Files' tab.
4. Execute the below queries in the Developer Console.
  • SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId=<<Id og the document>>
    • 2 records will be returned
  • SELECT Id, Title FROM ContentDocument WHERE Id=<<ContentDocumentId from the above query>>
    • 2 rows will be returned
5. Set up the Debug logs
6. IN CLASSIC
Delete one of the uploaded files, by clicking on the 'Del' link besides the document under 'Files' related list.
OBSERVATION:
  • In Debug logs you will see that only the ContentDocumentLinkTrigger has got fired and the Debug statement present in that Trigger will get displayed.
  • The document you have deleted will be available under the 'Files' tab
  • On executing the above 2 queries you will observe that only 1 row is returned for the 1st query and 2 rows for the second query. i.e. Only the ContentDocumentLink is getting removed.
7. IN LIGHTNING:
Open the object record and delete the 2nd uploaded file, by clicking on the 'Del' link besides the document under 'Files' related list.
OBSERVATION:
  • In Debug logs you will see that only the ContentDocumentTrigger has got fired and the Debug statement present in that Trigger will get displayed.
  • The document you have deleted will no longer be available under the 'Files' tab
  • On executing the above 2 queries you will observe that no row is returned for the 1st query and 1 row for the second query (the one related to the 1st document). i.e. Both the ContentDocument and the ContentDocumentLink have got removed.
Vidensartikelnummer

000381623

 
Indlæser
Salesforce Help | Article