Grant record access on standard objects by referencing a custom sharing reason (row cause) in Apex, the same way you do for custom objects. Previously, programmatic shares on standard objects were limited to the Manual row cause. A share that uses a custom sharing reason isn't deleted when the record owner changes, and a descriptive reason appears on the record's sharing page.
Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.
How: Define a custom sharing reason for a standard object that has a share object, such as AccountShare or OpportunityShare, by deploying a SharingReason component through the Metadata API. Then reference the reason in Apex with the same Schema syntax that you use for custom objects, as in Schema.AccountShare.RowCause.Compliance_Team__c.
AccountShare accShare = new AccountShare();
accShare.AccountId = '001xx000003DGa2AAG';
accShare.UserOrGroupId = '005xx000001Sv2sAAC';
accShare.AccountAccessLevel = 'Edit';
accShare.RowCause = Schema.AccountShare.RowCause.Compliance_Team__c;
insert accShare;
Custom sharing reasons are available only for standard objects that have an associated share object and whose org-wide default is set to Private or Public Read-Only. Objects on the detail side of a master-detail relationship, which have no share object, aren't supported. You can create up to 10 custom sharing reasons per standard object using the Metadata API.