[SalesForce] How to deploy Sharing rules using Eclipse

I am trying to deploy Sharing rules (Criteria Based) from one Org to another Org using eclipse and when I try to do it gives an error "Component type not permissible in destination Organization".

Best Answer

In the project metadata, all the sharing rules will be inside a folder named "sharingRules" and each of them will be named as "ObjectAPIName.sharingRules"

The package.xml should mention the sharing rule correctly as "ObjectAPIName.SharingRuleName" and it must come under the correct type in package.xml. A sample package.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Lead.testShareRule</members> 
         <name>SharingCriteriaRule</name>
    </types>
    <types>
        <members>*</members> 
        <name>SharingOwnerRule</name>
    </types>
    <types>
        <members>Account.*</members>
        <name>SharingTerritoryRule</name>
    </types>
    <version>33.0</version>
</Package>

A sample file of sharing rule is :

<?xml version="1.0" encoding="UTF-8"?>
<SharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
    <sharingCriteriaRules>
        <fullName>AccountCriteriaShareWithCEO</fullName>
        <accessLevel>Edit</accessLevel>
        <accountSettings>
            <caseAccessLevel>Read</caseAccessLevel>
            <contactAccessLevel>Edit</contactAccessLevel>
            <opportunityAccessLevel>Edit</opportunityAccessLevel>
        </accountSettings>
        <criteriaItems>
            <field>Name</field>
            <operation>startsWith</operation>
            <value>Test</value>
        </criteriaItems>
        <description>my account criteria rule description</description>
        <label>AccountCriteriaShareWithCEO</label>
        <sharedTo>
            <role>CEO</role>
        </sharedTo>
    </sharingCriteriaRules>
</SharingRules>

Also please see the following links:

  1. Sharing rules in the metadata api - https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_sharingrules.htm
  2. Package.xml for sharing rules - https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/manifest_samples.htm#manifest_sharing

Thanks

Related Topic