You need to sign in to do that
Don't have an account?
Walter@Adicio
How do I pull field labels instead of field names out of the describe results for an object?
This is what I have right now, but I want the select options list to show the field label to the user and pass the field name when selected by the user.
Schema.DescribeSObjectResult obj = Quote_Comment__c.sObjectType.getDescribe(); Map<String, Schema.SObjectField> objFields = obj.fields.getMap(); for( String fieldName : objFields.keySet() ) { orderByOptions.add(new SelectOption(fieldName,fieldName )); }
Schema.SobjectField can be converted to describefieldResult. Then using describeFieldResult.getLabel(), you can get the field labels. In your case:
for(String fieldName : objFields.keySet()){
Schema.SobjectField s = objFields.get(fieldname);
DescribeFieldResult f = s.getDescribe();
orderByOptions.add(new SelectOption(fieldName,f.getlabel()));
}
All Answers
Schema.SobjectField can be converted to describefieldResult. Then using describeFieldResult.getLabel(), you can get the field labels. In your case:
for(String fieldName : objFields.keySet()){
Schema.SobjectField s = objFields.get(fieldname);
DescribeFieldResult f = s.getDescribe();
orderByOptions.add(new SelectOption(fieldName,f.getlabel()));
}
Is there anyway to get around the limit in field describes? I'm using something similar, but I have to put a limit of 10 otherwise we have errors about too many field describes. Excerpt from the code, getting Account History fields:
Any insight would be appreciated greatly!
- Eva