---
schema_version: "1"
id: 109f98c7046713d6a3e0cd0b475b5e289dc1cdb0f85666956348a31139142dec
title: Database Operations Run in User Mode by Default, Not System Mode
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/release-notes/262-0-0/rn_apex_default_user_mode.md
canonical_url: https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_user_mode.htm&release=262.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 280372bfdd583501b1e32dec833977cee5f3be7412bd272dbc3b244489c1a88c
description: Take advantage of an enhanced Apex security model that protects your data though default object- and field-level access enforcement. Apex database operations, such as SOSL and SOQL queries, DML statements, and Database methods, now run in user mode by default. In user mode, database operations enforce the sharing rules, field-level security, and object permissions of the current user. In earlier API versions, database operations default to system mode, which means that the current user can access all data regardless of their permissions.
products:
  - Cross Cloud
release: "262"
---
# Database Operations Run in User Mode by Default, Not System Mode

Take advantage of an enhanced Apex security model that protects your data though default object- and field-level access enforcement. Apex database operations, such as SOSL and SOQL queries, DML statements, and Database methods, now run in user mode by default. In user mode, database operations enforce the sharing rules, field-level security, and object permissions of the current user. In earlier API versions, database operations default to system mode, which means that the current user can access all data regardless of their permissions.

**Where:** This versioned change applies to API version 67.0 and later. The change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

**Why:** The new “secure by default” security paradigm prevents data visibility risks that can occur when you omit an access mode on database operations. Database operations bypass object- and field-level security settings only if you explicitly set them to run in system mode. This requirement promotes intentionality and ensures that you use system mode only when necessary.

**How:** To determine the access mode of a database operation regardless of the API version, we recommend that you always set an access mode explicitly.

To set the access mode for a SOSL or SOQL query, use the `WITH USER_MODE` or `WITH SYSTEM_MODE` clauses.

```java
Account acc = [SELECT Id FROM Account WHERE Name = 'Singha' WITH USER_MODE LIMIT 1];
```

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-release-notes-salesforce_release_notes-262-0-0-production-enus/e945111b-3e0a-4011-accc-d5949363bfcc/images/icon_note.png)

Note The WITH SECURITY\_ENFORCED clause is removed as of API version 67.0. Use WITH USER\_MODE instead.

To set the access mode for a DML operation, use the `as user` or `as system` keywords.

```java
Account a = [SELECT Id, Name 
   FROM Account
   WHERE Support__c = 'Premier' 
   WITH USER_MODE];
a.Rating = 'Hot';
update as user a;
```

To set the access mode for a `Database` or `Search` method, set the `accessLevel` parameter to `AccessLevel.USER_MODE` or `AccessLevel.SYSTEM_MODE`.

```java
Account a = Database.query('SELECT Id, Name 
    FROM Account 
   WHERE Rating = \'Hot\'',  AccessLevel.USER_MODE);
```

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-release-notes-salesforce_release_notes-262-0-0-production-enus/e945111b-3e0a-4011-accc-d5949363bfcc/images/icon_note.png)

Note If you set a database operation to user mode, the operation respects the user’s sharing rules and overrides the calling class’s sharing declaration. However, if you set the operation to system mode, the sharing declaration of the calling class determines whether the operation respects the user’s record-level permissions.

#### See Also

- [_Apex Developer Guide:_ Set an Access Mode for Database Operations](https://developer.salesforce.com/docs/atlas.en-us.262.0.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm)
- [_Apex Developer Guide_: Apex Security and Sharing Model](https://developer.salesforce.com/docs/atlas.en-us.262.0.apexcode.meta/apexcode/apex_security_sharing_chapter.htm)
- [_Apex Developer Guide_: Enforce Security with Field and SObject Describe Methods](https://developer.salesforce.com/docs/atlas.en-us.262.0.apexcode.meta/apexcode/apex_classes_field_object_describe.htm)