Activity Forums Salesforce® Discussions What are the differences between system mode and user mode in Salesforce?

  • Mohit

    Member
    October 4, 2016 at 7:33 am

    Hello Ajit,

    System Mode is nothing but running apex code by ignoring user's permissions. 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. All apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks like developer console and standard controllers.

    User Mode is nothing but running apex code by respecting user's permissions and sharing of records. Only standard controllers and anonymous blocks like developer console run in user mode.

    Apex Triggers always run in System Mode irrespective of sharing settings, is a myth. Because if your apex trigger is calling a class declared using “WITH SHARING”, then all sharing rules for the context user will apply during trigger execution. If you apex triggers is expecting to query all records and that code is running under WITH SHARING context, then user’s profile will come into play.

  • SAMI

    Member
    November 23, 2016 at 5:53 am

    Hi Ajit,

    There is difference of execution perspective between User & System Mode. Like in

    User Mode :

    All Permissions granted to user are enforced while execution

    System  Mode :

    All permissions granted to user are ignored while execution. We can understand this by following example :

     

    Standard controller gets executed in user mode for e.g. if we use Account as standard controller in VF page and user does not have access permission to
    access Account then he will get insufficient privileges error message.

    Custom controller and custom extension always run in system mode ( ignoring user's permission) but we can run it in user mode using a new keyword
    "with sharing".

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos