如何获取选定对象对象的字段标签名称而不是 Visualforce 页面中的字段 API 名称?
How to get the field label names for the Selected Object objects instead of Field API Names in Visualfroce page?
public class Testing4 {
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public String selectedObject {get; set;}
public String selectedField {get; set;}
Public Testing4()
{
selectedObject = 'account';
}
public List<SelectOption> getObjectNames()
{
List<SelectOption> objNames = new List<SelectOption>();
List<String> entities = new List<String>(schemaMap.keySet());
entities.sort();
for(String name : entities)
{
objNames.add(new SelectOption(name,name));
}
return objNames;
}
public List<SelectOption> getObjectFields()
{
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
fieldNames.add(new SelectOption(fieldName,fieldName));
}
return fieldNames;
}
}
如何获取 Selected Object 对象的字段标签名称而不是 Visualfroce 页面中的字段 API 名称?
这里我正在获取所选对象的所有字段 API 名称,但我只需要字段标签(不是 API 名称)。
试试这个从 Salesforce 对象字段中获取标签名称:
Schema.getGlobalDescribe().get('ObjectName').getDescribe().fields.getMap().get('FieldName').getDescribe().getLabel();
您的代码:
public List<SelectOption> getObjectFields()
{
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
String fName = fieldMap.get(fieldName).getDescribe().getLabel();
fieldNames.add(new SelectOption(fName, fName));
}
return fieldNames;
}
public class Testing4 {
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public String selectedObject {get; set;}
public String selectedField {get; set;}
Public Testing4()
{
selectedObject = 'account';
}
public List<SelectOption> getObjectNames()
{
List<SelectOption> objNames = new List<SelectOption>();
List<String> entities = new List<String>(schemaMap.keySet());
entities.sort();
for(String name : entities)
{
objNames.add(new SelectOption(name,name));
}
return objNames;
}
public List<SelectOption> getObjectFields()
{
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
fieldNames.add(new SelectOption(fieldName,fieldName));
}
return fieldNames;
}
}
如何获取 Selected Object 对象的字段标签名称而不是 Visualfroce 页面中的字段 API 名称?
这里我正在获取所选对象的所有字段 API 名称,但我只需要字段标签(不是 API 名称)。
试试这个从 Salesforce 对象字段中获取标签名称:
Schema.getGlobalDescribe().get('ObjectName').getDescribe().fields.getMap().get('FieldName').getDescribe().getLabel();
您的代码:
public List<SelectOption> getObjectFields()
{
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
List<SelectOption> fieldNames = new List<SelectOption>();
for (String fieldName: fieldMap.keySet())
{
String fName = fieldMap.get(fieldName).getDescribe().getLabel();
fieldNames.add(new SelectOption(fName, fName));
}
return fieldNames;
}