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

获取所有字段

SObjectType esalesTemp = Schema.getGlobalDescribe().get('EsalesTemp__c');
Map 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);
}

获取特定的选项列表字段:

@AuraEnabled
    public 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;
    }

你可能感兴趣的:(SalesForce,SalesForce学习)