+ Start a Discussion
garybgaryb 

Do triggers on an object fire if the object is being deleted because its parents are being deleted?

Hi all,

I have a set up where Object A is a parent of Object B. There is a trigger on delete of an Object B record to delete a record of type Object C related to the Object B record being deleted (ideally, Object C would be a child of B, but we can't do this unfortunately).

So: A is a parent of B, C is related to B but not via a parent/child relationship. And a trigger on B deletes the relevant C object when B is deleted.

If we delete a record of type A, it will delete B (because of the parent/child relationship) and - what I would expect anyway - the trigger on B will delete the relevant C object.

Except that it doesn't. Should it? I opened a clean developer account, put a trigger on B that just prints a debug statement, created the relevant data, deleted A and - nothing in the log.

FWIW, A is the standard Account object, B is the standard Event object, and C is a custom object we've developed.

Thanks in advance for your help!
Best Answer chosen by Admin (Salesforce Developers) 
arnt72arnt72
IIRC deleting a parent does not fire delete triggers on child records. It is described in the APEX Language Reference but I do not have the link here right now.

All Answers

BritishBoyinDCBritishBoyinDC
From what I can see, objects related via lookup are not deleted in this circumstance - only children in a master-detail relationship.

To delete the records in Object C, you need to set a before delete trigger to look for related records...
garybgaryb
Thanks for the quick response!

I do have a trigger on B to delete the related C object but it doesn't seem to be firing. My suspicion is that because B is being deleted because its parent object (A) is being deleted, the trigger is not firing.

Wondering what other people's experiences are?
BritishBoyinDCBritishBoyinDC
If necessary, try putting a trigger on the pre-delete on Object A - not ideal, but that might work
arnt72arnt72
IIRC deleting a parent does not fire delete triggers on child records. It is described in the APEX Language Reference but I do not have the link here right now.
This was selected as the best answer
ne-rm-teamne-rm-team
I can agree with the last post because i made the same expiriance. A delete-trigger on a child object will not fire, just because you deleted the parent record. If you want to catch this, you have to use a befor delete trigger in your parent-object and look for related child objects.
 
Regards
SO
garybgaryb
Indeed, after going through support, the solution was to write a trigger that deleted the objects. Delete Triggers do not fire if an object is being deleted because it's parents are being deleted.

Thanks to all those who replied!