function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ken LewisKen Lewis 

ContactShare.ContactId Not Writeable Even Though External Access = Private

Hi All,
I have External Sharing Model enabled so that all Accounts and Contacts are editable by internal users and private for external users.  So Accounts are set to Public Read/Write for the Default Internal Access and set to Private for the Default External Access.  Contacts are set to Controlled by Parent for both Default Internal and External Access.

I want to make specific Accounts and Contacts editable for some external users based on criteria.  I am attempting to insert a ContactShare record, but I receive the error:
Field is not writeable: ContactShare.ContactId
Research suggests that this error is expected if the default sharing settings are set to a level that is equal to or more accessible than the level you are attempting to set with your ContactShare record. (https://developer.salesforce.com/forums?id=906F00000008yIBIAY)

It seems to me that I should be able to insert this ContactShare record since my Default External Access is set to Private for Accounts and Contacts, but that I am getting the error because my Default Internal Access is set to Public Read/Write. 

Does anyone have any insight into how I might be able to use Apex Managed Sharing in this way (in conjunction with an External Sharing Model)?

I'm hoping to leverage the External Sharing Model and avoid have to set all Account and Contacts to Private both internally and externally and use a Public Group to assign access programmatically for both types of users.  
 
Best Answer chosen by Ken Lewis
ShashankShashank (Salesforce Developers) 
By design, the contactId field becomes non-writable even when the internal OWD is public. I'n afraid you may have to go for the public group workaround.

All Answers

ShashankShashank (Salesforce Developers) 
By design, the contactId field becomes non-writable even when the internal OWD is public. I'n afraid you may have to go for the public group workaround.
This was selected as the best answer
Ken LewisKen Lewis
Thank you, @Shashank for your reply.  I couldn't find a definitive explanation in the docs, so this is very helpful.