No Way to Run Trigger After Object Deleted

Posted by awbranch on 17-Sep-2014 09:40

I want to run a trigger on a parent record when a child record is deleted. However I don't seem to be able to make this happen. I'm using Rollbase version 2.1.0.3.

Idea 1: In the child record add a "Run Trigger on Related Record" that will call the trigger on the parent record after the child record is deleted.

Oh No - The "After Delete" is disabled. Why is this?

Idea 2: Run an "Object Script" trigger on the child record After Delete

Oh No - The "After Delete" is disable again. No explanation as to why again.

Idea 3: Read documentation (doh!) - Hmmmm, nothing in there about the "After Delete" checkbox being disabled under certain circumstances. However I find this nugget on page 270.

When record is attached or detached using UI links in Related List component the system
runs "After Update" triggers on both sides

Ah-Ha - I'll add an After Update to the parent record. When the child record is deleted the trigger will run.

I create a trigger on the parent object, set it to run "After Update" to create an activity log entry on "Any Update" to the object.

In the parent objects view page, I change a text field value on the parent record. I check the activity log. Yup an entry was added to the activity log as expected.

I delete a child record. I check the activity log. Oh No - Nothing added to the activity log. How could this be?

So I'm out of ideas here am I missing something obvious?

Posted by awbranch on 19-Sep-2014 07:57

Romain,

That works!!! Thank you so much, I really appreciate it.

Can I send you a box of chocolates?

Andrew

All Replies

Posted by pvorobie on 17-Sep-2014 10:07

Can you run triggers "before delete" instead?

Posted by awbranch on 17-Sep-2014 10:34

No, The trigger I want to run on the parent needs to be run after the child has been removed.

Posted by Gian Torralba on 17-Sep-2014 10:34

Hello,

Using the after delete trigger will somehow not recognize the parent record of the child being deleted because it is already "deleted". Try using the before delete trigger to handle your logic instead.

Thank you,
Gian

Posted by pvorobie on 17-Sep-2014 10:36

I'm not sure I understand all reasoning correctly, but when record is deleted - its gone. So it may not be possible to do what you want.

Posted by awbranch on 17-Sep-2014 11:22

If there is no way to run a trigger after an object is deleted, its seems odd that Rollbase would even have a "After Delete" checkbox that is there but disabled. The documentation say nothing about this.

What about my idea 3? Why wouldn't the parent's record fire "After Update" when a related document is deleted, as the documentations states that it should?

It appears there is no way for a parent record to be notified when one of its children are removed.

Posted by pvorobie on 17-Sep-2014 16:20

Tracking as PSC00314155

Posted by awbranch on 17-Sep-2014 16:42

Does PSC00314155 mean that this is a bug?

Posted by pvorobie on 17-Sep-2014 22:21

This is enhancement request:

Need to allow running "Run Triggers on Related Records" triggers after record's delete to notify related records

I will look into this issue more closely.

Posted by awbranch on 18-Sep-2014 07:51

Ok thanks. The documentation states: "When record is attached or detached using UI links in Related List component the system runs "After Update" triggers on both sides"

So either I'm not configuring something correctly or its a regression bug of some kind.

Posted by awbranch on 18-Sep-2014 13:24

Is there any proposed workaround?

Posted by pvorobie on 18-Sep-2014 14:12

I'm investigating, but I don't have any workaround at this time.

Posted by romain.pennes@foederis.fr on 19-Sep-2014 03:08

Hello,

We also had this need in the past, to be able to run triggers on related records after a record is deleted.

As awbranch is stating, this is not possible using the "Run Trigger on Related Record" or the "Object script" types of triggers.

However, there is a workaround using the "Update Field Value" type of trigger. This trigger can be processed after delete.

You just have to chose an arbitrary field to update (it doesn't matter which one because the record is gonna get deleted anyway), and you can write "rbv_api.runTrigger" statements to call a trigger of the parent's record.

We have been using this workaround for more than a year, and it is working fine for us, even though we would prefer being able to use "Run Trigger on Related Record" or the "Object script" types of triggers.

Kind regards,

Romain.

Posted by awbranch on 19-Sep-2014 07:57

Romain,

That works!!! Thank you so much, I really appreciate it.

Can I send you a box of chocolates?

Andrew

Posted by romain.pennes@foederis.fr on 19-Sep-2014 08:30

You're welcome.

I would love that, but I'm in France, so this may be quite hard to achieve!

Romain.

Posted by awbranch on 19-Sep-2014 09:07

No problem. Send me your address and I'll make it happen.

awbranch@gmail.com

This thread is closed