No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
SharingRules
Represents a set of sharing rules. SharingRules enables you to share records with a set of users, using rules that specify the access level of the target user group. It extends the Metadata metadata type and inherits its fullName field. For more information, see “Sharing Rules Overview” in the Salesforce online help.
Declarative Metadata File Suffix and Directory Location
SharingRules are stored in their corresponding entity directory and the file name matches the entity name. For example, the accountSharingRules directory contains an Account.sharingRules file for account sharing rules. SharingRules for custom objects are stored in the customObjectSharingRules directory, which contains files with the .sharingRules extension such as ObjA__c.sharingRules, where ObjA refers to the developer name of a custom object type.
Version
SharingRules components are available in API version 24.0 and later.
Fields
The following information assumes that you are familiar with implementing sharing rules for standard objects and custom objects. For more information on these fields, see “Sharing Settings Overview” in the Salesforce online help.
| Field | Field Type | Description |
|---|---|---|
| fullName | string | The unique identifier for API access. The fullName can contain only underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores. This field is inherited from the Metadata component. |
AccountSharingRules
Represents the sharing rules for accounts. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | AccountCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | AccountOwnerSharingRule[] | List that defines user membership-based rules. |
CampaignSharingRules
Represents the sharing rules for campaigns. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | CampaignCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | CampaignOwnerSharingRule[] | List that defines user membership-based rules. |
CaseSharingRules
Represents the sharing rules for cases. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | CaseCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | CaseOwnerSharingRule[] | List that defines user membership-based rules. |
ContactSharingRules
Represents the sharing rules for contacts. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | ContactCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | ContactOwnerSharingRule[] | List that defines user membership-based rules. |
LeadSharingRules
Represents the sharing rules for leads. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | LeadCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | LeadOwnerSharingRule[] | List that defines user membership-based rules. |
OpportunitySharingRules
Represents the sharing rules for opportunities. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | OpportunityCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | OpportunityOwnerSharingRule[] | List that defines user membership-based rules. |
AccountTerritorySharingRules
Represents the sharing rules for account territories. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| rules | AccountTerritorySharingRule[] | List that defines user membership-based
rules. The list
of acceptable values for the sharedFrom fields
are:
|
CustomObjectSharingRules
Represents the sharing rules for custom objects. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | CustomObjectCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| ownerRules | CustomObjectOwnerSharingRule[] | List that defines user membership-based rules. |
UserSharingRules
Represents the sharing rules for users. With user sharing rules, you can share members of a group with members of another group. It extends the SharingRules metadata type and inherits its fullName field.
| Field | Field Type | Description |
|---|---|---|
| criteriaBasedRules | UserCriteriaBasedSharingRule[] | List that defines user criteria-based rules. |
| membershipRules | UserMembershipSharingRule[] | List that defines user membership-based rules. |
Declarative Metadata Sample Definition
The following is the definition of two account owner-based sharing rules. The file name corresponds to Account.sharingRules under the accountSharingRules directory. In this definition, ownerRules corresponds to AccountOwnerSharingRule.
1<?xml version="1.0" encoding="UTF-8"?>
2<AccountSharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
3 <ownerRules>
4 <fullName>G1Dev_G2New</fullName>
5 <sharedFrom>
6 <group>G1Dev</group>
7 </sharedFrom>
8 <sharedTo>
9 <group>G2New</group>
10 </sharedTo>
11 <accountAccessLevel>Read</caseAccessLevel>
12 <caseAccessLevel>None</caseAccessLevel>
13 <contactAccessLevel>Read</contactAccessLevel>
14 <name>G1Dev_G2New</name>
15 <opportunityAccessLevel>Edit</opportunityAccessLevel>
16 </ownerRules>
17 <ownerRules>
18 <fullName>G2New_R1New</fullName>
19 <sharedFrom>
20 <group>G2New</group>
21 </sharedFrom>
22 <sharedTo>
23 <roleAndSubordinates>R1New</roleAndSubordinates>
24 </sharedTo>
25 <accountAccessLevel>Edit</accountAccessLevel>
26 <caseAccessLevel>Read</caseAccessLevel>
27 <contactAccessLevel>Edit</contactAccessLevel>
28 <name>G2New_R1New</name>
29 <opportunityAccessLevel>None</opportunityAccessLevel>
30 </ownerRules>
31</AccountSharingRules>The following is the definition of a user criteria-based sharing rule and a user membership-based sharing rule. The file name corresponds to User.sharingRules under the userSharingRules directory.
1<?xml version="1.0" encoding="UTF-8"?>
2<UserSharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
3 <criteriaBasedRules>
4 <fullName>shareUsers2</fullName>
5 <sharedTo>
6 <group>Asia_Division</group>
7 </sharedTo>
8 <criteriaItems>
9 <field>FirstName</field>
10 <operation>equals</operation>
11 <value>John</value>
12 </criteriaItems>
13 <name>shareUsers2</name>
14 <userAccessLevel>Read</userAccessLevel>
15 </criteriaBasedRules>
16 <membershipRules>
17 <fullName>shareUsers1</fullName>
18 <sharedTo>
19 <group>South_America_Division</group>
20 </sharedTo>
21 <sharedFrom>
22 <group>Asia_Division</group>
23 </sharedFrom>
24 <name>shareUsers1</name>
25 <userAccessLevel>Read</userAccessLevel>
26 </membershipRules>
27</UserSharingRules>The following shows a sample package.xml file.
1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3 <types>
4 <members>UserRule</members>
5 <name>UserCriteriaBasedSharingRule</name>
6 </types>
7 <types>
8 <members>*</members>
9 <name>UserMembershipSharingRule</name>
10 </types>
11 <version>32.0</version>
12</Package>