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

ondelete trigger not fired, when parent object being deleted

Hi all,


just wrote a trigger that should be executed every time an attachment is deleted ("before delete attachment"). As long as I just delete attachments, this one works like a charm.

Now comes the big "but": If I delete an email with an attachment or even a case that contains an email with attachment, the trigger is not fired, although all related objects (case, email, attachment) are being removed in the process.


Why won't the trigger work as its supposed to be?





unfortunately for you, that's just how works.  the summary of the link below is


"Cascading delete operations. Records that did not initiate a delete do not cause trigger evaluation."


You can read the rest of the topic to get info.





If you really need your trigger to run, you can put delete triggers on the parent objects (like cases and emails), and query for their attachments and do one of the following:

1) perform the same logic that you did in the attachment trigger.  you probably want to move this code into a common class / method

2) you could also try performing explicit deletes on the attachments and that should force the attachment trigger to run.




Thanks for the information!


Bad luck for me and - imho - another example of bad design. Now I need X triggers instead of one...