Apex クラス定義識別子の意味を教えてください

イシュー

  • Apex クラスを定義する際に、識別子に public とか global とか設定しますけど、private / protected / public 以外はわかりません。(by サラリーマンJAVAエンジニア)

参考

シンタックス

private | public | global [virtual | abstract | with sharing | without sharing | (none)] class ClassName [implements InterfaceNameList | (none)] [extends ClassName | (none)] { // The body of the class }

public と global の違いについて

The public access modifier declares that this class is visible in your application or namespace. The global access modifier declares that this class is known by all Apex code everywhere. All classes that contain methods defined with the webService keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global.

パブリックアクセス修飾子は、このクラスは、アプリケーションまたは名前空間に表示されていることを宣言します。 グローバルアクセス修飾子は、このクラスがどこでも、すべてのApexコードによって知られていることを宣言します。 webService キーワードで定義されたメソッドが含まれているすべてのクラスはglobalとして宣言する必要があります。メソッドまたは内部クラスをglobalとして宣言されている場合、外側の、トップレベルのクラスは、グローバルとして定義する必要があります。

  • public はアプリケーションの外からは見えないけど、global はアプリケーションの外からも見えるとおっしゃられているようですが、ここでいうアプリケーションというのは「組織+(無名名前空間)」 or 「名前空間」と考えてよろしいんでしょうか?

with sharing について

The with sharing and without sharing keywords specify the sharing mode for this class. For more information, see Using the with sharing or without sharing Keywords.

with sharing と without shareing キーワードは、このクラスの共有モードを指定します。詳細については、with sharing または without sharing キーワードの使い方を参照してください。

The with sharing keyword allows you to specify that the sharing rules for the current user be taken into account for a class. You have to explicitly set this keyword for the class because Apex code runs in system context. In system context, Apex code has access to all objects and fields— object 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. The only exceptions to this rule are Apex code that is executed with the executeAnonymous call and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user. For more information on executeAnonymous, see Anonymous Blocks.

with sharing キーワードは、現在のユーザーがクラスに考慮されるべき共有ルールを指定することができます。 Apex コードはシステム制御下で実行されるため、このキーワードをクラスに明示的に設定する必要があります。 システム制御下では、Apexコードは、すべてのオブジェクトと項目オブジェクト権限へのアクセス権を持ち、共有ルールでは、項目レベルのセキュリティは、現在のユーザー用には適用されません。 これはそのコードが原因で、そのユーザーにとっての隠し項目またはオブジェクトによって、実行に失敗しないようにするためです。 このルールの唯一の例外は、executeAnonymousコール と Apex内Chatter により実行されたApex Code です。 executeAnonymousは、常に現在のユーザーのすべての権限を使用して実行されます。 executeAnonymousの詳細については、Anonymous Blocksを参照してください。

  • with sharing (シェアリングルール)で実行するということは、システム制御下(権限無双)で実行するということ