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
HGSHGS 

Delete trigger not working in Master-Detail object deletion.

Hello Community !!

 

We have 2 custom object, in master-detail relationship.

 

When master record is deleted, the associated detail records are also deleted automatically.

 

And, we have a after-delete trigger on the detail object.

 

The problem is, that though the trigger works fine when we delete the detail records directly, it does not fire when the master is deleted, and thus the detail records are deleted.

 

Any pointers ?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess

Triggers are only invoked for data manipulation language (DML) operations that are initiated or processed by the Java
application server. Consequently, some system bulk operations do not currently invoke triggers. Some examples include:
• Cascading delete operations. Records that did not initiate a delete do not cause trigger evaluation.
• Cascading updates of child records that are reparented as a result of a merge operation
• Mass campaign status changes
• Mass division transfers
• Mass address updates
• Mass approval request transfers
• Mass email actions
• Modifying custom field data types
• Renaming or replacing picklists
• Managing price books

All Answers

kerwintangkerwintang

I'm not sure why this is the behavior in Salesforce. But as a workaround, why not add the same delete trigger logic from the detail table onto the delete trigger logic of the master table? Will this work? :)

 

Best Regards,

Kerwin

HGSHGS

:-)

 Yes, I've already thought about that work-around, and would have to do it if there isn't any solution. 

But was wondering, is there a constraint / bug, as this would affect a lot of code that we regularly write on the same lines.

 

VarunCVarunC
I think It's not a Constraint, and neither is a BUG, because they never implemented the relationship this way :( .. and since they never implemented it to work as you or me wanted this can never be a bug. But they must understand that this way they are FORCING us to eventually use our Most Precious SOQL CALLS .. :( ..
Ron HessRon Hess

Triggers are only invoked for data manipulation language (DML) operations that are initiated or processed by the Java
application server. Consequently, some system bulk operations do not currently invoke triggers. Some examples include:
• Cascading delete operations. Records that did not initiate a delete do not cause trigger evaluation.
• Cascading updates of child records that are reparented as a result of a merge operation
• Mass campaign status changes
• Mass division transfers
• Mass address updates
• Mass approval request transfers
• Mass email actions
• Modifying custom field data types
• Renaming or replacing picklists
• Managing price books

This was selected as the best answer
Keith654Keith654

This bevavior:

 

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

comes as quite a surprise.

 

I have a "before delete" trigger on the last detail object of a master-detail relationship chain intended to propagate the cascading delete to a second master-detail chain. (The total number of master-detail relationships I need exceeds the current allowed maximum.) This seemed like a clean and simple approach but is not sufficient given the above.

 

Please give more emphasis in your documentation to this. I don't remember ever seeing it in the documentation.