---
schema_version: "1"
id: ea365944a3c837cb66f2e7987eeaaf2bace96869a354e7dc6f1f5d1a52d144b5
title: Apex Classes Enforce Sharing Rules by Default
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_enforce_sharing.md
canonical_url: https://help.salesforce.com/s/articleView?id=release-notes.rn_apex_default_enforce_sharing.htm&release=262.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: c358cd06b07a0ebdd335b39ea5eba0e9b4d57eec28d7c7f6d60ec00c911e26f9
description: Take advantage of an enhanced Apex security model that protects your data through default record access enforcement. Apex classes without an explicit sharing declaration now default to with sharing mode, which enforces org-wide sharing settings and custom sharing rules. In earlier API versions, Apex classes without an explicit sharing declaration default to without sharing mode, with some exceptions. The without sharing mode bypasses sharing rules and allows the current user to access all records.
products:
  - Cross Cloud
release: "262"
---
# Apex Classes Enforce Sharing Rules by Default

Take advantage of an enhanced Apex security model that protects your data through default record access enforcement. Apex classes without an explicit sharing declaration now default to `with sharing` mode, which enforces org-wide sharing settings and custom sharing rules. In earlier API versions, Apex classes without an explicit sharing declaration default to `without sharing` mode, with some exceptions. The `without sharing` mode bypasses sharing rules and allows the current user to access all records.

**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 if you omit sharing declarations on Apex classes. To bypass sharing rules, you must now have an explicit without sharing declaration on the Apex class. This requirement promotes intentionality and ensures that you use the `without sharing` declaration only when necessary.

**How:** To determine an Apex class’s sharing mode with confidence, we recommend that you always include an explicit sharing declaration. Otherwise, these factors determine the sharing mode of an Apex class without an explicit sharing declaration.

- If you compile the Apex class in API version 67.0 and later, then an omitted sharing declaration defaults to `with sharing`. If the class inherits from another class, its sharing mode is defined by the parent’s sharing mode.
- If you compile the Apex class in API version 66.0 and earlier, then an omitted sharing declaration defaults to `without sharing`. However, these exceptions apply.
    - If the class is part of an inheritance chain, and any class in that chain is saved as API version 67.0 and later, an omitted sharing declaration defaults to `with sharing`.
    - If the class is an Aura controller or an `@AuraEnabled` method called from a Lightning web component, an omitted sharing declaration defaults to `with sharing`.
    - If the class isn’t an Apex entry point, its sharing mode is defined by the sharing mode of the calling class.

#### See Also

- [_Apex Developer Guide:_ Use the with sharing, without sharing, and inherited sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.262.0.apexcode.meta/apexcode/apex_classes_keywords_sharing.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)