1
0

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.

【salesforce】Apexで項目レベルセキュリティを実装

Posted at

with sharing キーワードでは共有ルールのみ適用される、
オブジェクトレベルセキュリティと項目レベルセキュリティ (FLS のように省略されていることが多い) を自分で実装する必要があります。
以下の項目レベルセキュリティの実装例となります。
(Lightning componentのコントローラ実装例となっていますが、APEXとしては汎用的に利用可能)

@AuraEnabled
public static List<Expense__c> getExpenses() {
    
    // Check to make sure all fields are accessible to this user
    String[] fieldsToCheck = new String[] {
        'Id', 'Name', 'Amount__c', 'Client__c', 'Date__c', 
        'Reimbursed__c', 'CreatedDate'
    };
    
    Map<String,Schema.SObjectField> fieldDescribeTokens = 
        Schema.SObjectType.Expense__c.fields.getMap();
    
    for(String field : fieldsToCheck) {
        if( ! fieldDescribeTokens.get(field).getDescribe().isAccessible()) {
            throw new System.NoAccessException();
        }
    }
    
    // OK, they're cool, let 'em through
    return [SELECT Id, Name, Amount__c, Client__c, Date__c, 
                   Reimbursed__c, CreatedDate 
            FROM Expense__c];
}
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?