You need to sign in to do that
Don't have an account?
Sunil Bagul
Field label in Apex
i want to find the label for field and i am using this code to find that,it is returning me label but for Type picklist lable is Type but it is returning Account Type,any help just to get label as Type?
String type='Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(type);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
System.debug('##Field API Name='+fieldName);// list of all field API name
System.debug(fieldMap.get(fieldName).getDescribe().getLabel());//It provides to get the object fields label.
}
String type='Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(type);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
System.debug('##Field API Name='+fieldName);// list of all field API name
System.debug(fieldMap.get(fieldName).getDescribe().getLabel());//It provides to get the object fields label.
}
I believe the standard type field always returns label as 'ObjectType Type' . I tried for Case and opportunity and it returns label as "Case Type"
and 'Opportunity Type'.
if you want to override this then either you have to hardcode label as 'Type' If the filedname=='type' or you need to do string manipulation like this
but in fields section it shows label as Type only