I'm going through CRUD and Field-Level Security (FLS) from Lightning Components Developer Guide, and the following code for Field-Level Security validation doesn't make any sense for me in terms of good development practices:
// Obtain the field name/token map for the Expense object
Map<String,Schema.SObjectField> m = Schema.SObjectType.ns__Expense__c.fields.getMap();
for (String fieldToCheck : expenseAccessFields) {
// Check if the user has access to view field
if (!m.get(fieldToCheck).getDescribe().isAccessible()) {
// Pass error to client
throw new System.NoAccessException()
// Suppress editor logs
return null;
}
}
Isn't an ultimate goal is to hide ONLY the fields that the current user shouldn't have access to? And another question - what do you use to control Field-Level Security [in Apex for Lightning] as the most efficient/convenient method?