7

Has anybody bumped into this error when spinning a new scratch org?

Here's how this happened. I created a new scratch org and created 2 objects. One had a lookup field to the other. Then I pulled that change locally using SFDX. Later I changed the lookup relationship to a Master-Detail one. However SFDX never picked up the change.

Now I am trying to re-spin the scratch org(it expired) and I am getting this Cannot set sharingModel to ReadWrite on a CustomObject with a MasterDetail relationship field.

SF's documentation says that the sharingModel indicates the organization-wide defaults for the object. Link: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/customobject.htm

Again based on SF's documentation: The detail record inherits the sharing and security settings of its master record.

So I am thinking that this is happening because the detail record should inherit the sharingModel from the parent but instead it's specified as ReadWrite in the metadata file. How should I handle this?

  • 2
    Idea is that in case if you have master-detail relationship, then there is no reason specify sharing in metadata file for child sObject type, since it is inherited from parent. Try to remove sharing definition from metadata file from child object – kurunve Jul 30 '18 at 17:33
  • I am actually trying to set the sharingModels to ControlledByParent. I think this might solve it. – Arthlete Jul 30 '18 at 17:37
  • @kurunve I tried what you suggested but SF gives me Must specify a sharing model value for the Custom Object – Arthlete Jul 30 '18 at 18:33
  • 1
    I don't know of a way around this, but you might want to submit a bug report. – sfdcfox Jul 30 '18 at 18:57
  • @sfdcfox I don't think my sf account allows me to submit a bug report based on my last attempt. – Arthlete Jul 30 '18 at 19:21
4

Okay this is how I resolved it. Based on the Metadata Field Types I set the sharingModel and the externalSharingModel both to ControlledByParent and everything built correctly!

EDIT When I tried pushing to the newly created scratch Org I got this error Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field. The xml metadata file clearly states that there is a master-detail relationship. Everything in the org seems okay too but it did not want to push until I changed the sharingModel and the externalSharingModel to ReadWrite again. So I guess that's a workaround but then to spin the org those have to be changed to ControlledByParent again.

0

In the scatch org where you initially made this change, you might need to force a re-pull of the object sharing model by making some other minimal change to the object (e.g. Description or Label). Once you have metadata in a consistent state it should work fine to push to the new scratch org. You need to both push the M-D relationship field and ControlledByParent in the same push.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.