SharingReason defines an Apex sharing reason for a custom object: a named explanation for why Apex managed sharing was implemented. Apex managed sharing uses Apex code to grant record access programmatically. The metadata defines the reason, not the access itself.
A sharing reason is not a runtime share record or a declarative sharing rule. Creating or deploying a SharingReason does not grant access to any records; Apex implements the sharing.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
Required API identity of the reason. Custom sharing reason names use the __c suffix. Supply this value when creating, updating, or deleting the definition. |
label |
Required descriptive text, limited to 40 characters. The label is distinct from the API identity. |
Behavior and Constraints
Sharing reasons are scoped to a custom object. A reason defined for one object is not a reason definition for another object.
For Apex managed sharing on custom-object records, only users with the "Modify All Data" permission can add or change the sharing. This restriction concerns the sharing on records, not the metadata operations used to define a reason.
Apex managed sharing access is maintained when the record owner changes or is deactivated. An ownership change therefore does not, by itself, explain or remove access granted through this mechanism.
Deployment and Retrieval
SharingReason supports creating, updating, and deleting sharing reason definitions. The fullName must be supplied for all three operations. A definition also requires a label of no more than 40 characters; the label does not replace the API name.
Sharing reasons appear within the owning CustomObject metadata under sharingReasons. For example, that container can hold a reason whose fullName is recruiter__c and whose label is Recruiter.
SharingReason does not support the * wildcard in package.xml. When selecting this type directly in a deployment or retrieval manifest, list explicit members rather than using a wildcard.
Relationships
The owning object contains the reason definition. Translation metadata connects localized reason text to that definition. A translation reference does not establish that Apex uses the reason or that existing share records carry it.
Referenced By
-
CustomObject:sharingReasonscontains the object's sharing reason definitions. -
CustomObjectTranslation:namein sharing-reason translation entries identifies the underlying reason.
Reported Issues
-
Use the API name in code, not the displayed label. A 2018 discussion reports that Apex and API references use the reason's API name, while the label appears in the Reason column when viewing record sharing. The label can be translated through Translation Workbench. For a
Recruiter__creason defined onJob__c, the example reference isSchema.Job__Share.rowCause.Recruiter__c. See the RowCause discussion. -
A String value alone does not prove that a custom sharing reason exists. In the same 2018 discussion, a developer reported that an expression such as
Schema.Job__Share.rowCause.Recruiter__creturns aString, not a dedicated reason type. For diagnosing dynamically suppliedRowCausevalues,Job__Share.rowCause.getDescribe().getPicklistValues()was reported to expose both custom reasons and standard allowable values. The returned values must therefore be distinguished when checking specifically for a custom reason. See the String typing and describe findings.
Common Questions
Does deploying a SharingReason grant record access?
No. It deploys a reason definition. Apex must implement the sharing that grants access to records.
Can I retrieve all SharingReason components with a wildcard?
Not by using * for SharingReason in package.xml. Direct selection of this type requires explicit members.
Why does Apex managed sharing remain after the record owner changes?
Apex managed sharing access on custom-object records is maintained when the owner changes or is deactivated. That persistence is part of its behavior.
Should Apex use the sharing reason label or API name?
Use the API name, such as Recruiter__c. The community report distinguishes this identity from the label shown in the sharing interface and translated through Translation Workbench.
Does a RowCause String prove that it is a defined custom reason?
No. The reported describe results include both custom reasons and standard allowable values. String typing alone does not establish that the value identifies a defined custom sharing reason.