Last active
August 7, 2017 08:36
-
-
Save danic85/a5519c6591bce94cf4e7c7064506c50b to your computer and use it in GitHub Desktop.
Lightning FLS. Throw exception if any field is not accessible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://developer.salesforce.com/page/Lightning_Security#Access_Control_in_Apex_Controllers_and_Supporting_Classes | |
List<String> fields = new List<string>(); // Add your fields to check here | |
String objectName = ''; //Add your object name here | |
Map<String,Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap() | |
for (String fieldToCheck : fields) { | |
// Check if the user has access to view field | |
if (!fieldMap.get(fieldToCheck).getDescribe().isAccessible()) { | |
//also pass error to client | |
throw new System.NoAccessException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment