Loading

ContentDocument and ContentDocumentLink Trigger Behavior When Deleting Files in Salesforce Classic vs. Lightning Experience

Дата публикации: Jun 22, 2026
Описание

In Salesforce, files attached to records are stored as ContentDocument objects. The relationship between a file and a record is represented by a ContentDocumentLink object — each ContentDocumentLink links one ContentDocument to one record.


When a file is deleted, the Apex trigger behavior differs between Salesforce Classic and Lightning Experience. This difference is important for developers who write custom Apex triggers on the ContentDocument or ContentDocumentLink objects, as the trigger that fires depends on which experience the user is working in.

Решение

Behavior in Salesforce Classic

When a user deletes a file from the Files related list in Salesforce Classic, Salesforce deletes only the ContentDocumentLink record — it does not delete the ContentDocument itself. As a result:

 

  • Only the ContentDocumentLink trigger fires.
  • The ContentDocument trigger does not fire.
  • The deleted file remains visible under the Files tab (because the ContentDocument still exists).
  • After deletion, querying ContentDocumentLink by the parent record ID returns one fewer row, while querying ContentDocument still returns the same number of rows.

Behavior in Lightning Experience

When a user deletes a file from the Files related list in Lightning Experience, Salesforce deletes both the ContentDocument and its associated ContentDocumentLink records. As a result:

 

  • Only the ContentDocument trigger fires.
  • The ContentDocumentLink trigger does not fire.
  • The deleted file is removed from the Files tab.
  • After deletion, querying ContentDocumentLink by the parent record ID returns no rows for the deleted file, and querying ContentDocument returns one fewer row.

How to Verify This Behavior

To verify trigger behavior in your org:

 

  1. Create two Apex "before delete" triggers — one on ContentDocument and one on ContentDocumentLink. Add a System.debug() statement in each trigger.
  2. Upload two files to any record's Files related list.
  3. Query ContentDocumentLink filtered by the parent record ID — two rows are returned (one per file).
  4. Query ContentDocument using the ContentDocumentId values returned — two rows are returned.
  5. Enable debug logs for your user.
  6. In Classic: Delete one file via the Del link in the Files related list. Review debug logs — only the ContentDocumentLink trigger fires. Query again — ContentDocumentLink returns one row; ContentDocument still returns two rows.
  7. In Lightning Experience: Delete the second file via the Del link. Review debug logs — only the ContentDocument trigger fires. Query again — ContentDocumentLink returns no rows; ContentDocument returns one row.
Номер статьи базы знаний

000381623

 
Загрузка
Salesforce Help | Article