You need to sign in to do that
Don't have an account?

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!
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!
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
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.