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
SysAdmin David CornfordSysAdmin David Cornford 

CaseAccessLevel

I have changed the sharing rules on various records and the role structure for my organisation, but now users are unable to edit cases, change status or owner; or email from the case.

The error message that users see on the screen is:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ShareUserPermission caused an unexpected exception, contact your administrator: ShareUserPermission: execution of AfterUpdate caused by: System.SObjectException: Field is not writeable: CaseShare.CaseAccessLevel: Trigger.ShareUserPermission: line 16, column 1

I also receive an email as below:
**
Apex script unhandled trigger exception by user/organization: 005900000010qIR/00D90000000iHod
ShareUserPermission: execution of AfterInsert
caused by: System.SObjectException: Field is not writeable: CaseShare.CaseAccessLevel
Trigger.ShareUserPermission: line 16, column 1
**

I think the issue is similar to this:
https://help.salesforce.com/apex/HTViewSolution?id=000149002&language=en_US

But I have no idea how to resolve it. Help!
Andreas MeyerAndreas Meyer
Hi David,

it would be helpful if you post the ShareUserPermission trigger code. Keep in mind that if you try to change an object (passed by the trigger) in trigger UPDATE AFTER you have to requery that object since it is write protected. That is of course different while you are in trigger UPDATE BEFORE.

Best,
Andreas
RamuRamu (Salesforce Developers) 
I guess your orgnization uses apex sharing through an apex class 'ShareUserPermission'  alongside standard sharing rules. As you stated that you modifed the standard sharing rules and role hierarchy, the apex sharing may not be holding good hence the error. I suggest that you disable the apex class 'ShareUserPermission' ON YOUR SANDBOX FIRST or modify the apex code to comply with the changes you made from the UI and see if it resolved the issue.