Apex Inherited Sharing キーワードの使用サンプル

環境
salesforce

構文
コール元のクラスの共有ルールを強制実行するには、
クラスの宣言時に inherited sharing キーワードを使用します。
inherited sharing を指定した Apex クラスは、Apex トランザクションへの
エントリポイントとして使用される場合 (フローなど)、または以下のものとして使用される場合には、with sharing として実行されます。

サンプルコード

1.Apex側コード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public inherited sharing class InheritedSharingClass {
public List<Contact> getAllTheSecrets() {
return [SELECT Name FROM Contact];
}
}
public inherited sharing class InheritedSharingClass { public List<Contact> getAllTheSecrets() { return [SELECT Name FROM Contact]; } }
public inherited sharing class InheritedSharingClass {
    public List<Contact> getAllTheSecrets() {
        return [SELECT Name FROM Contact];
    }
}

2.Visualforce コード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<apex:page controller="InheritedSharingClass">
<apex:repeat value="{!allTheSecrets}" var="record">
{!record.Name}
</apex:repeat>
</apex:page>
<apex:page controller="InheritedSharingClass"> <apex:repeat value="{!allTheSecrets}" var="record"> {!record.Name} </apex:repeat> </apex:page>
<apex:page controller="InheritedSharingClass">
    <apex:repeat value="{!allTheSecrets}" var="record">
        {!record.Name}
    </apex:repeat>
</apex:page>

説明
inherited sharing のある Apex クラスとその Apex コードの Visualforce 呼び出しを
宣言します。inherited sharing 宣言により、
実行ユーザーが共有アクセス権を持つ取引先責任者のみが表示されます。
この宣言が省略されている場合、安全でないデフォルトの動作により、
ユーザーが参照権限を持たない取引先責任者も表示されます。

IT

Posted by arkgame