We have a few use cases where we want to prevent a Contact from being unlinked from an Opportunity.
We’ve implemented logic that automatically adds a Contact to an Opportunity when a Meeting’s Parent Type is set to “Opportunity.” Since Opportunities often have multiple meetings and the same Contact may attend several we want to ensure the relationship between the Contact and Opportunity remains intact under certain conditions.
Use Cases:
Use Case 1:
When a Contact is removed from a Meeting, we’d like to implement a logic hook on the Meetings module. This hook would check if the Contact is still linked to any other Meeting associated with the same Opportunity. If not, only then should the Contact be unlinked from the Opportunity.
Use Case 2:
In the standard UI, if a Contact is associated with any Meeting under the Opportunity, prevent users from manually unlinking the Contact from the Opportunity.
Use Case 3:
In the mobile app, apply the same rule: if the Contact is tied to any related Meeting, block unlinking from the Opportunity.
Use Case 4:
At the API level, we want to block DELETE calls that would remove the relationship between the Contact and the Opportunity—again, unless the Contact is no longer tied to any related Meetings.
Ideally, we’d like to centralize this with a single before_relationship_delete logic hook on the Opportunities module to enforce these rules consistently across UI, mobile, and API.
Has anyone in the community implemented something similar or have suggestions on the best approach?
Additionally, we will need to execute before all other before_relationship_delete logic hooks such as
$hook_array['before_relationship_delete'][] = [ 1, 'denorm_field_watcher', null, '\\Sugarcrm\\Sugarcrm\\Denormalization\\Relate\\Hook', 'handleDeleteRelationship', ];