You need to sign in to do that
Don't have an account?
AvLav
sObject fields name locate to a selectlist
Hy!
I want to use the name of the sObject field in seleclist. How can I get this name?
I read the apex guide, but I don't undestand very well the sobject describe result. I need a STRING, but the method result is a SCHEMA.DESCRIBESOBJECTRESULT.
I need something similar:
public List<SelectOption> getCateg() { List<SelectOption> options = new List<SelectOption>(); for (Account acc : [select id, Name from Account]) { String cat = acc.Name; options.add(new SelectOption(cat, cat)); } return options; }
But I need the name of the field (accountname, type, website, etc) insted of the value.
This should work:
public List<SelectOption> getCateg() { List<SelectOption> options = new List<SelectOption>(); Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();Schema.SObjectType leadSchema = schemaMap.get('Account');Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();for (String fieldName: fieldMap.keySet()) { options.add(new SelectOption(fieldName, fieldName)); } return options;}
/G