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

can user create record using with sharing apex class if user don't have access on object

Can user create a record If he don't have access on object and executing apex class(Creates new record on that object) having with sharing keyword?
VinayVinay (Salesforce Developers) 
The with sharing keyword allows you to specify that the sharing rules for the current user are considered for the class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user.

Check below reference for more details.

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Hi Vinay,

Does it mean that the user cannot create a record, if he don't have access to object and executing the "with sharing" class?
Abhishek BansalAbhishek Bansal

In order to answer your question, No, User cannot a create a record if he doesn't have access to object and class is running in a with sharing mode.

Abhishek Bansal.