2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

忘れがちなsharingキーワードの特徴

Last updated at Posted at 2022-04-23

用語解説

with sharing

  • 共有ルールを適用する

  • 適用されるのはログインユーザの共有ルール

without sharing

  • 共有ルールを適用しない

  • 呼び出し元のクラスがwith sharingを使っていても、without sharingを宣言しているクラスには共有ルールが適用されない

inherited sharing

  • 呼び出し元のクラスの共有モードに従う

忘れがちな特徴

各記法での共有モード

  • メソッド

    • 定義されているクラスの共有モードに従う
  • 内部クラス

    • コンテナクラスから継承しない
  • 継承クラス

    • 親→子へ継承される
  • トリガ

    • sharingキーワードが指定できない

    • デフォルトでwithout sharingが適用される


sharingキーワードを省略したとき

自身のキーワードが省略されている場合

  • 他クラスからの呼び出しなし

    • without sharingが適用される
  • 他クラスからの呼び出しあり

    • 呼び出し元の共有ルールに従う

inherited sharingを宣言していて、呼び出し元クラスのキーワードが省略されている場合

  • with sharingが適用される

匿名ApexやConnect in ApexでApexを実行するとき

sharingキーワードに関わらず、ログインユーザの共有ルールが適用される


参考文献

Using the with sharing, without sharing, and inherited sharing Keywords

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?