You need to sign in to do that
Don't have an account?
Sumeet_Force
Apex not running in System mode even if [with sharing] is not used.
Hi,
I have a VF page and some apex code in related controller. The VF is ran by a user having limited access based on his profile. However the code tries to update a contact which results in a privilege error and says [Update access denied for Contact] which seems an issue for currently runnign user. This is fine as user profile doesnt allow him to edit/update Contacts. However if I have not used [with sharing], then ideally it should run in System mode which is somehow not happening. Can someone pls help by pointing out issue or some direction pls ?
I have a VF page and some apex code in related controller. The VF is ran by a user having limited access based on his profile. However the code tries to update a contact which results in a privilege error and says [Update access denied for Contact] which seems an issue for currently runnign user. This is fine as user profile doesnt allow him to edit/update Contacts. However if I have not used [with sharing], then ideally it should run in System mode which is somehow not happening. Can someone pls help by pointing out issue or some direction pls ?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm
Can you explicitily mark the class as without sharing and let me know what the output in that case
Just now tried using without sharing and also by removing Edit permission on Contact for running user and it somehow failed with same error:
19:57:37.0 (24197099)|EXCEPTION_THROWN|[EXTERNAL]|System.VisualforceException: Update access denied for Contact, controller action methods may not execute
As per this article, "with sharing" and "without sharing" keywords has nothing to do with CRUD permission, they only play role in selecting records on sharing basis.
So in your profile, if you do not have Edit permission on Contact object, you wont be able to update that contact record even if your class is without sharing. Without sharing will only help you to query the contact records on which do not have access.
Hi Ravi,
Main lines causing the code:
Contact c = new Contact (Id=variableId);
c.Field = 'SOME VALUE HERE';
update c;
thats the main part causing error....it also does other things but above code i.e update statement is part causing the error.
Hi Ravi,
Everywhr its mentioned that in system mode , it will run in system context and can perform almost everthing ...not very sure if its restricted to only the query part.
snippet from link you mentioned says same thing: read below pls:
System mode is nothing but running apex code by ignoring user's permissions. For example, logged in user does not have create permission but he/she is able to create a record.
In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren't applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user.