System Mode and User Mode in Salesforce

System Mode and User Mode in Salesforce

System Mode and User Mode in Salesforce

System mode means running apex code by ignoring user’s permissions. User mode means running apex code by respecting user’s permissions and sharing of records. Let’s understand it in more detail.

System Mode and User Mode in Salesforce

System Mode

  • System mode means running apex code by ignoring user’s permissions. For example, if logged in user does not have permission to one object but they will able to access that object.
  • In system mode, Apex code has access to all objects and fields 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.
  • In Salesforce, all apex code run in system mode. It ignores user’s permissions. Only exception is anonymous blocks like developer console and standard controllers. Even runAs() method doesn’t enforce user permissions or field-level permissions, it only enforces record sharing.

 

User Mode

  • User mode means running apex code by respecting user’s permissions and sharing of records. For example, if logged in user does not access to objector a record, then they will not be able to access that object..
  • In User mode, Profile level permissions, field-level security, and sharing rules are applied for the current user.
  • In Salesforce, only standard controllers and anonymous blocks like developer console run in user mode.

 

Here is list of all operations in salesforce and their execution mode:

  • Apex Trigger: System Mode
  • Anonymous Apex: User Mode
  • Apex Webservices (SOAP API and REST API) – System
  • Chatter in Apex – User Mode
  • Email Service – User Mode
  • All types of Jobs – System Mode
  • Test method with System.runAs() – User Mode
  • Test method without System.runAs() – System Mode
  • Validation Rule: System Mode
  • Auto-Response Rule – System Mode
  • Assignment Rule: System Mode
  • Workflow Rule: System Mode
  • Escalation Rule: System Mode
  • All Types of calculation behind the formula, Rollup Summary – System Mode
  • Process Builder: System Mode
  • Visual Workflow or flow – User Mode
    • if flow is called from Process Builder – System Mode
    • if flow is called from Workflow – System
    • if flow is called from Apex – (depends on with or without sharing of apex class)
    • if flow is called from Custom Button – System
    • if flow is embed in Visualforce – Depends on VF Page context
    • if flow is called from REST API – System
  • Approval Process – System
  • Publisher Action – System
  • InvocableMethod
    • if this is called from flow – User
    • if this is called from Process Builder (does it depends on with or without sharing is specified on that Class) – System
    • if this is called from REST API – (depends on with or without sharing of the class)
  • Custom Button – System
  • Visualforce Page (StandardController) – User Mode
  • Visualforce Page (StandardController with extension) – System Mode
  • Visualforce Page (Custom Controller)
    • depends on with or without sharing of the controller

 

Here is the order of execution in salesforce salesforce order of execution

Permanent link to this article: https://www.sfdcpoint.com/salesforce/system-mode-and-user-mode-in-salesforce/

2 comments

  1. Great read! Thank you for such useful insights. Visit here for latest tech courses on salesforce service cloud training

    • Yi on September 24, 2021 at 5:54 am
    • Reply

    Visualforce Page (StandardController with extension) – User Mode

Leave a Reply

Your email address will not be published.