+ Start a Discussion
David WeryDavid Wery 

DX : Scratch org Configuration - Sharing Settings

Hi all,

We need to package and deploy in a DX environment the following code :
CaseShare userShare = new CaseShare();
userShare.CaseId = <case_id>;
userShare.UserOrGroupId = <user_id>;
userShare.CaseAccessLevel = 'Edit';
insert userShare;

The execution of the deployment process fails :
sfdx force:source:push -u <scratchorglabel>

Field is not writeable: CaseShare.CaseId (66:23)
Field is not writeable: CaseShare.UserOrGroupId (67:23)
Field is not writeable: CaseShare.CaseAccessLevel (69:27)
Field is not writeable: CaseShare.CaseAccessLevel (71:27)
DML operation Insert not allowed on CaseShare (73:13)

Apparently, this occurs when the sharing settings (here the Case object) is set to 'Public". The case object meta-data has sharing settings set to private but, based on what I see, it looks to be ignored during the push (see case.object-meta.xml below)
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
Can someone help me on getting the insert of the sharing rule correctly packaged (unmanaged)?

Thomas MinneyThomas Minney
Hello David, did you ever find a solution for this? I am hitting the same problem as you have described except for the Contact object.