+ Start a Discussion
KognozKognoz 

Metadata API: Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field

Hi All,

We have had a managed package for a couple of years that works alongside an external app which does remote depoyments using the Metadata API. Specifically the external app creates custom fields in 2 custom objects of the package.

These two custom objects are in a Master-Details relationship, and the OWD are Public Read/Write for the master one, and Controlled By Parent on the detail/child one.

The remote deplyments via the Metadata API use the File deployment, and in the XML for the detail/child object we always included the XML:
<sharingModel>ControlledByParent</sharingModel>

In the last couple of weeks this has been causing the remote deployments via the Metadata API to fail with the following message:
Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field

It looks that something has changed in the way the Metadata API works. Could somebody shed some light into it ?

Thanks
Fernando

Best Answer chosen by Kognoz
Ian StockIan Stock
I've had the same problem for a few weeks now, and stumbled on the resolution to "Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field" when deploying through change sets. I wasn't having the problem through the IDE though.
The resolution is to add the "MasterDetail relationship field" into the change set, even if you haven't changed it or the Sharing / OWD.
I'm assuming if you don't have the custom field in your package / object in the IDE either, then you'd probably get the same error.

All Answers

Ian StockIan Stock
I've had the same problem for a few weeks now, and stumbled on the resolution to "Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field" when deploying through change sets. I wasn't having the problem through the IDE though.
The resolution is to add the "MasterDetail relationship field" into the change set, even if you haven't changed it or the Sharing / OWD.
I'm assuming if you don't have the custom field in your package / object in the IDE either, then you'd probably get the same error.

This was selected as the best answer
KognozKognoz
Ian, thank you very much for your reply, and you are right bang on !

After some trial and error iterations we added the master field to the detail deplyment file, even if it already exists in the target org, and that did the trick. So it looks that indeed there has been a change in the way the Metadata API works for deployments of custom fields which are in a Master-Detail relationship.

Thanks !
Ian StockIan Stock
No problem. If only the error message had the words "in the changeset/package" at the end, I'd have figured it out much sooner. I was stumped because both orgs had the field, so wasn't sure what it was getting at or how to resolve it.


Nihar SharmaNihar Sharma
Hello Ian,

Thanks for sharing your experience. really helpful to me and my team :)

-Nihar
venkat davuluri 31venkat davuluri 31
Hello All,

Could you explain it how to do it.
I've created another changed set for this and added the object. 
What would be the next step to add the masterdetail field.

Thank you 
Venkat
Valdas Stasevicius 5Valdas Stasevicius 5
@Venkat,

When selecting what to add to your change set, select custom fields and then select the field that defines master-detail relationship. 

Ian's  solution worked for me