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
XactAndyXactAndy 

Managing many to many relationships - deletion

We have set up a number of many to many relationships in our App using intermediate relationship objects with a pair of lookup relationships. Obviously, when a related object is deleted, any dependent relationship objects should also be deleted. Can I just check that we must manage this ourselves, and that we could do this in one of two ways:

1.  Implementing a new delete button on the related object types and associating it with an s-control that first cleans up any dependent relationship objects and then deletes the object itself; I assume we will need to hide the existing delete button and upload the new one to replace.
2. Using Apex triggers to do the same automatically on delete of the related object.

(1) would be preferable as we don't currently use Apex in our app.

Any other simpler suggestions would be appreciated. We had thought of using master detail relationships, but you can't have more than one master detail relationship per custom object anyway.

Thanks

Andy
DevAngelDevAngel
Sounds like overriding the Delete Button should do the trick.  Apex code is a much better solution since the trigger would be applied regardless of where and how the record is deleted (ie from the api or from another context).