system mode in Salesforce

System Mode and User Mode in Salesforce

System mode implies running apex code by overlooking the user's authorizations. User mode understands the running apex code by concerning the user’s support and sharing of records.

Let’s discuss system mode and user mode in more detail.

System Mode: 

  • System mode derives the running code by disregarding the user’s consent. For example: If a logged-in user wants to create a record in system mode. Create permission is not required for the creation of records in this mode.
  • Apex code approaches to all objects and field approvals, sharing rules, field-level security is not applied for the recent user. So that it ensures you that apex code won’t disregard to run because they don’t have the field or object permission.
  • In salesforce, We all know that all the apex code runs in System mode because it ignores the user's approvals. Just an exception is obscure squares like architect console and standard controllers. Without a doubt, even the runAs() method doesn't implement user assets or field-level approvals, it just maintains record sharing.

dont miss out iconDon't forget to check out: DML Statements vs Database Methods in Salesforce

User Mode:

  • User mode is similar to running the apex code with respect to user’s support and their sharing of records. For example:  If a logged-in user wants to create a record in user mode. Create permission is required for the creation of records in this mode.
  • In this mode, field-level security, field approvals, sharing rules, and profile level approvals are put in for recent users.
  • In Salesforce, only standard controllers and developer consoles run in user mode.

Let’s think about the operation and their mode of execution in Salesforce...

Here is the list of operations that runs on System Mode and User Mode.

  1. Apex trigger - System Mode
  2. All types of Jobs like Batch and scheduler apex -  System Mode
  3. Anonymous Apex - User Mode
  4. Apex Web Services (means SOAP API and REST API) - System Mode
  5. Auto-Response Rule - System Mode
  6. Assignment Rule - System Mode
  7. Chatter - User Mode
  8. Email Service - User Mode
  9. Test method with System.runAs() -  User Mode
  10. Test method without System.runAs() - System Mode
  11. Validation Rule -  System Mode
  12. Workflow Rule - System Mode
  13. Escalation Rule - System Mode
  14. Formula Field - System Mode
  15. Rollup Summary Field -  System Mode
  16. Process Builder - System Mode
  17. Visual Workflow or flow - By default it runs on User Mode
    1. if it is called from the Process Builder - System Mode
    2. if it is called from the Workflow -  System Mode
    3. if it is called from Apex then it depends on with or without sharing of apex class.
    4. if it is called from Custom Button - System Mode
    5. if it is embedded in Visualforce – Depends on VF Page context
    6. if it is called from REST API – System Mode
  18. Approval Process - System Mode
  19. Publisher Action - System Mode
  20. InvocableMethod
    1. if this method is called from flow – User mode
    2. if this method is called from Process Builder – System mode
    3. if this method is called from REST API – (depends on with or without sharing of the class)
  21. Custom Button - System Mode
  22. Visualforce Page 
    1. StandardController – User Mode
    2. StandardController with extension – System Mode
    3. Custom Controller - It depends on with or without sharing the Apex controller class.

dont miss out iconCheck out another amazing blog by Shweta here: Component Events in Salesforce Lightning Framework

References: biswajeetsamal, sfdcpoint

Popular Salesforce Blogs