Prevent Deletion of module record and related module records

We have a need to avoid accidental deletion of a module record based on some conditions. These conditions will probably be indicated by a custom field on the module which can be examined during the deletion process.

I have 3 questions:

1 - Is the before_delete logic hook the best place / method to do this ?

In other words, records are likely to be deleted either singly or via the List View bulk delete functionality. When 'Delete' is actioned, I'm thinking if the condition test is in the before_delete logic hook, an 'exit' could be achieved avoiding deletion of that record.

2 - does the primary record deletion occur first, followed by relationship records, related module records ?

So by interrupting the delete on the primary record, we don't delete any associated records.

3 - does anyone have some sample code showing how to trap / exit from the before_delete logic hook. The basic documentation is not giving this level of detail ?

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Architecture/Logic_Hooks/Module_Hooks/before_delete/

Thanks

Neil

Parents Reply Children