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
Nitish Yadav 45Nitish Yadav 45 

Changing Case Owner in With sharing class

I have few question on "with Sharing" and "without Sharing" keyword in apex,
 
In my Org the OWD for case is Public read only. I have one class where i am updating owner id of the case to some hard coded user id. The running user doesn't have edit access to that case and the class is running in "with sharing" mode but still he is able to update the owner of that case with that hard-coded user Id but when i am updating any other field along with owner id then the code is giving exception "insufficient Access on cross reference entity". The running user profile doesn't have "transfer records", "transfer Cases",  "Modify All Data" and not even "Modify All" on Case object. I tried checking UserRecordAccess table and i am getting only read access to that record for the running user and even no Implicit sharing as well.

Can someone please help me here : 
Did anyone face this issue before ??
Is my assumption correct that with sharing class doesn't check the access if we update only "ownerId" for that record ??

Thanks in advance.

 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Nitesh,

As per the answer in the stack exchange in the below question this seems to be expected behaviour.

https://salesforce.stackexchange.com/questions/73392/does-with-sharing-only-apply-to-1st-entry-point-of-code


universally required/unique indexes/etc are always enforced in Apex Code, regardless of the sharing model

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,