Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Lightning FLS. Throw exception if any field is not accessible.
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