I have a plugin that runs in a custom entity, the plugin looks for all opportunities that should be related to that record and associates them to the custom entity.

But sometimes an opportunity shouldn't be associated with the custom entity anymore. So before associating everything I wanted to un-link these opportunities, is it possible?

I tried using record.RelatedEntities.Clear(); or record.RelatedEntities.Remove(relationship_name); but it didn't work.

Thank you for your help.