0

Salesforce document says - If an extension extends a standard controller, the logic from the standard controller doesn’t execute in system mode

If i am using an extension extnding standard controller, will the entire logic run in user mode or just the one which is part of stndrd controller?

Suppose i am using account standard controller extended by an extension however i am doing dml on account child.... Will this dml be performed in user mode or system mode? Practical exmple says its user mode but document says system mode ( because this isn't part of account standard controller )

Sara
  • 1,165
  • 1
  • 11
  • 24
  • Can you please make few things clear. First para you are referring Standard controller and extension. Second para custom controller and extension and third para again standard controller and extension. Second points in first para you are saying SF document says standard controller doesn’t execute in system mode and in last document says system mode – Tushar Sharma Jun 18 '16 at 08:20
  • I have made an edit for second para where by mistake I wrote custom instead of standard. – Sara Jun 19 '16 at 01:53
  • In first para I mean that sf doc says logic from standard cont only executes in user mode. In last para I am not talki g about logic from standard controller because it is child object dml so ideally it should execute in system mode, which isnt the case. – Sara Jun 19 '16 at 01:55
  • The basic rules are as Susanoo Chidori wrote as an answer (which was subsequently deleted). Extensions can run as "with sharing" or "without sharing", just like any other class. If you want to update the children as "without sharing", then use "without sharing" in your class definition. – sfdcfox Jun 21 '16 at 04:28
  • Sfdcfox, this isnt happening in real. Inspite mentioning without sharing, we need to give modify all access specifically. This shouldnt really be happening. So the scenario is, i am using an extenstion extending standard controller and making dml on child object of the object whose standard controller I am using. I am using without sharing keyword but when I have this class executed by a non system admin user, it throws error - insufficient cross reference entity. I go back to this child object and provide modify all permission, it works. – Sara Jun 22 '16 at 05:44

1 Answers1

-2

All custom controllers and extension controller run in system mode. Consequently, the current user's credentials are not used to execute controller logic, and the user's permissions and field-level security do not apply.

You can choose whether a custom controller or extension controller respects a user's organization-wide defaults, role hierarchy, and sharing rules by using the with sharing keywords in the class definition.

the below link Gives the detail view of sharing and without sharing Keyword.

https://developer.salesforce.com/docs/atlas.en-us.202.0.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm

JAK
  • 15
  • 5
  • Thanks but my question is what when an extension class extends a standard controller. https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_additional_controller.htm – Sara Jun 18 '16 at 06:20
  • Apex controller extension classes execute in system mode and thereby ignore user permissions and field-level security, you can choose whether they respect a user's organization-wide defaults, role hierarchy, and sharing rules by using the** with sharing keywords** in the class definition.

    https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_def.htm

    – JAK Jun 18 '16 at 06:25