Hello, When a record is attached/detached, we can use the after update event of a trigger to catch the event and perform our actions. Is there a way to detect what action is performed i.e. attach or detach from the trigger? Kindly let me know. Cheers. Iram
When a record is attached/detached, we can use the after update event of a trigger to catch the event and perform our actions. Is there a way to detect what action is performed i.e. attach or detach from the trigger? Kindly let me know.
We tried a way to achieve this and it is working fine.
The way is
> Create 2 triggers of type object script (one is on before update (Ex: Trigger1) and another one is on after update ((Ex: Trigger2).
> In Trigger 1, get the related records count and share the value to next trigger using setSharedValue API.
> In Trigger 2, get the latest related records count and compare with shared value.
> If latest count is greater than shared value then it is attached otherwise it is detached.
Note: It will work if you update record (attach/detach using lookup field) through edit page. It will not work if you attach/detach in record details page as 'Before Update" trigger will not work on attach/detach action. It is a known limitation.
Find attached app xml to illustrate the same. Update the record in Emp object and check the Emp object-> Trigger->Log.
Thanks and Regards,
Thanks Chandu for your reply, I'll try it out and let you know if I have any questions.
Thanks for the answer. I tried the above solution, however I was wanting it to work from the record details page rather than the new/edit page. I did try it out on the record details page but the trigger doesn't capture that unfortunately. Is there no other solution to this? Kindly let me know.
I don't have any solution for that problem. :(
Please raise a request in Ideas section for "Working with Before Update" trigger on attach/detach action in record details page.
Thanks and Regards,