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
Ivana MiserdaIvana Miserda 

Field is not writeable : CaseShare.UserOrGroupId

I am getting this error on the following line

CaseShare sharingForCase = new CaseShare();
sharingForCase.UserOrGroupID = sm.User__c;
sharingForCase.CaseId = singleCase.Id;
sharingForCase.CaseAccessLevel = 'Read';

where sm is a record of a custom object, and User__c is a lookup field to User.
Since I know you can actually create new CaseShare records and define for which user, does anybody have an ides/experience why this would cause an error?
Thank you in advance!
Best Answer chosen by Ivana Miserda
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please check if any CaseShare record already exist corresponding to sm.User__c for singleCase.Id? If so, remove that record and then try to fire the dml operation.

All Answers

Rochelle LoboRochelle Lobo
Have you verified that you have write access to the field under Users > Permission Set? If so, then the other thing, is maybe that it is looking for a User__c.Id, not the User__c object? I'm not sure if these help any but these are the two things I could think of.
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you please check if any CaseShare record already exist corresponding to sm.User__c for singleCase.Id? If so, remove that record and then try to fire the dml operation.
This was selected as the best answer