Apex managed sharing

When the sharing options aren't enough, or you simply need to share a given record automatically with a user or a group without changing its ownership, you can go with Apex managed sharing.

This kind of sharing is close to manual sharing but it is best used with Apex automation or external API calls (that is, the other system's operations directly into Salesforce).

To change an Apex managed sharing record, you need to have a Modify All Data permission: that's why this custom sharing is maintained even if the record changes ownership.

How to create Apex managed sharing rules is out of the scope of this book, and you need developers to achieve this kind of custom sharing. However, you may have to consider it when sharing policies are highly complex or the other sharing methods don't deliver the required level of sharing granularity.