Delete all incoming detail records when the master record is deleted

I have a master app and a detail app. The detail app is linked to the master app as incoming. I want to delete the associated detail records when a master record is deleted.

The master app has the following fields:

The calculation field hasItems calculates the incoming detail records.

The detail app has the following fields:

The delete field is later populated via automation and ensures the deletion of the sub-records.

And here are the automation for the masterapp:

And here the Automation for the detail App:

gif

When the master record is deleted, all detail records are deleted as well.

2 Likes

@Hans

This is an interesting one, thanks for posting. I have to admit I first read it on my phone and thought you were asking how to do it so I went off and worked through the problem myself and it is not as simple to solve as one might think.

Your solution is quite different from mine, which shows there are nearly always multiple ways to achieve the same thing, I like yours it is nice and neat and has no-code which I always think is good (mine had code).

One thing I would say is that it would be a lot easier to do if the Delete the current record didn’t trigger the When record is deleted when it is set to not be a trigger I am not sure if that is as intended or not:


or if the get previous values block worked on deleted records.

Hi Jason, I’m with you on that. Thanks for your feedback! I’m curious about your solution. Is there any reason not to share it? Often, not every approach is the best in every scenario.

Totaly and I can:
As you no doubt found the biggest battle is to not end up in a loop. Having looked at my solution again I am not convinced I have managed to avoid that! (I blame a lack of coffee!)
ScreenFlow

So for now the only relevant part of my solution that is different to yours is the way I was deleting the sub-records, which was by calling a simple automation to delete the collected sub-records.

I feel like I must be missing something and there is a way to put automation in the filter that works:

I also find it interesting that we can filter the automation trigger based on the value of a deleted record but can’t retrieve the previous values.

The other way I thought of solving the issue relied on the fact that every sub-record was always related to a master unless the master had been deleted, if that was the case then a simple automation to search the sub-records for any that are not related to a master and then delete any that were found:

This is probably the neatest way if the scenario fits.

As for the coffee, I can only help you with a virtual one. I just turned on the coffee machine.

Regarding your initial thought that a sub-record must always be linked to a master record, your solution fits perfectly. That approach hadn’t even crossed my mind.

1 Like

Actually isn’t that a cascaded delete? I would also put this into the “feature request” section, this is part of functionality in other LowCode platforms as well. Thanks for sharing the workaround @Hans!

@dirk_s That’s right, Dirk, this is cascading delete.

1 Like