6

I'm currently struggling in creating a ContactOwnerSharingRule via the Salesforce Metadata API.

I am using Ruby and the metaforce gem.

I am using the the create-method which calls out to the SOAP API. the call then looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://soap.sforce.com/2006/04/metadata" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://soap.sforce.com/2006/04/metadata">
  <env:Header>
    <ins0:SessionHeader>
      <ins0:sessionId>sessionId</ins0:sessionId>
    </ins0:SessionHeader>
  </env:Header>
  <env:Body>
    <ins0:create>
      <ins0:metadata xsi:type="ins0:ContactOwnerSharingRule">
        <ins0:fullName>foo</ins0:fullName>
        <tns:name>bar</tns:name>
        <tns:contactAccessLevel>Edit</tns:contactAccessLevel>
        <tns:sharedFrom>abc</tns:sharedFrom>
        <tns:sharedTo>def</tns:sharedTo>
      </ins0:metadata>
    </ins0:create>
  </env:Body>
</env:Envelope>

At this point it doesn't matter what I put into sharedFrom or sharedTo, because the error message is something else:

Required field is missing: Parent

I have not found a reference to a parent field in any documentation nor the Metadata WSDL file.

If I set the parent field to something, I get this error message:

 Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {http://soap.sforce.com/2006/04/metadata}parent element

So my question is:

Hast anyone ever created a SharingRule via the metadata API? And if so, how does the SOAP request look like?

2 Answers 2

1

I found a work-around for this issue, although I was never able to get it working as a CustomObjectCriteriaBasedSharingRule type, I was able to get this working with the (I think newer?) SharingCriteriaRule type. Here is some example XML:

<createMetadata xmlns="http://soap.sforce.com/2006/04/metadata">
  <metadata xsi:type="SharingCriteriaRule">
    <fullName>X__c.Public</fullName>
    <sharedTo>
      <allInternalUsers></allInternalUsers>
    </sharedTo>
    <criteriaItems>
      <field>Privacy__c</field>
      <operation>equals</operation>
      <value>Public</value>
    </criteriaItems>
    <accessLevel>Edit</accessLevel>
    <description>Grants standard users access to public views</description>
    <label>Public</label>
  </metadata>
</createMetadata>

The only syntactical difference between SharingCriteriaRule and CustomObjectCriteriaBasedSharingRule that I encountered was label/name fields. Hope this helps someone out there!

0

Looks like this may be a known issue, click the "This Issue Affects Me" link if you wish

Here is the link to the known issue:

https://success.salesforce.com/issues_view?id=a1p30000000T4Q3AAK

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .