Object Account has attribute Contacts, a one to many peer relation. Object Contact has matching attribute Accounts.
Account MainContact is a one to one reference to a Contact. It has no matching attribute in Contact.
When a Main Contact is added to Account.MainContact it is also inserted into Account.Contacts.
On the Account's form there is a separate form section that displays the list of Contacts. When a user trys to remove a Contact from that list, if the Contact they are trying to revove is actually the Account's MainContact I want to tell the user that they can't do that. But if the Contact they are trying to remove from the Account's contact list is not the Account's main contact, I just want to remove it from that list.
This should be easy to do, I think, but I have not been able to do it.
I can unconditionally remove the Contact from the list, but I can't do it conditionally, and I have tried all sorts of things.
If Contact WAS REMOVED FROM Account.Contacts AND RemovedContact = Account.MainContact Then
REPORT ERROR 'Main contact for the account cannot be removed from contact list.'