Skip to content

Instantly share code, notes, and snippets.

@tommyilpazzo
Last active August 26, 2016 14:15
Show Gist options
  • Save tommyilpazzo/e0865f4d7a8e52318295307c68c687bf to your computer and use it in GitHub Desktop.
Save tommyilpazzo/e0865f4d7a8e52318295307c68c687bf to your computer and use it in GitHub Desktop.
SFDC: Lightning Component APEX Controller
public with sharing class LightningComponentController {
@AuraEnabled
public static List<Object__c> getObjects() {
// Check to make sure all fields are accessible to this user
String[] fieldsToCheck = new String[] {
'Id', 'Name', 'Custom_Field1__c', 'Custom_Field2__c', 'Custom_Field3__c'
};
Map<String,Schema.SObjectField> fieldDescribeTokens =
Schema.SObjectType.Object__c.fields.getMap();
for(String field : fieldsToCheck) {
if(!fieldDescribeTokens.get(field).getDescribe().isAccessible()) {
throw new System.NoAccessException();
return null;
}
}
return [SELECT Id, Name, Custom_Field1__c, Custom_Field2__c, Custom_Field3__c
FROM Object__c];
}
@AuraEnabled
public static Object__c saveObject(Object__c object) {
// Check to make sure the object is updatable
if(!Schema.getGlobalDescribe().get('Object__c').getDescribe().isUpdateable()) {
throw new System.NoAccessException();
return null;
}
upsert object;
return object;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment