当前位置: 代码迷 >> 综合 >> Salesforce Apex 获取对象的所有字段并获取字段详情
  详细解决方案

Salesforce Apex 获取对象的所有字段并获取字段详情

热度:32   发布时间:2023-12-19 02:00:52.0

获取所有字段

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;}
  相关解决方案