获取所有字段
SObjectType esalesTemp = Schema.getGlobalDescribe().get('EsalesTemp__c');
Map<String,Schema.SObjectField> mfields = esalesTemp.getDescribe().fields.getMap();for (String s: mfields.keySet()) {SObjectField fieldToken = mfields.get(s);DescribeFieldResult selectedField = fieldToken.getDescribe();System.debug('===Name=='+selectedField.getName());System.debug('===Label=='+selectedField.getLabel());System.debug('===Type=='+selectedField.getType());Boolean isRequired = false;if (selectedField.isNillable() == false) {isRequired = true;}else{isRequired = false;}System.debug('===isRequired=='+isRequired);
}
获取特定的选项列表字段:
@AuraEnabledpublic static List<String> getTaskTypes(){List<String> result = new List<String>();Schema.DescribeFieldResult fieldResult = Task_RuleSetting__c.Type__c.getDescribe();List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();for( Schema.PicklistEntry f : ple){result.add(f.getLabel());} return result;}