You need to sign in to do that
Don't have an account?
psplrocks
retrieve field names for a contact
I want to bind the field names of a contact in a drop down list.
How can we get all the field names for a contact in Apex. is there any soql query to do so...
Map<String, Schema.SObjectField fieldMap = Schema.SobjectType.Contact.Contact.fields.getMap()
Once you have fieldMap, you can then iterate through the key set to get all the field names.
public List<SelectOption> getFieldList() { List<SelectOption> fieldNames = new List<SelectOption>(); for(String fieldName:fieldNames.keySet()) { fieldNames.add(new SelectOption(fieldName, fieldName); } return fieldNames; }
All Answers
Map<String, Schema.SObjectField fieldMap = Schema.SobjectType.Contact.Contact.fields.getMap()
Once you have fieldMap, you can then iterate through the key set to get all the field names.
public List<SelectOption> getFieldList() { List<SelectOption> fieldNames = new List<SelectOption>(); for(String fieldName:fieldNames.keySet()) { fieldNames.add(new SelectOption(fieldName, fieldName); } return fieldNames; }
Error: Compile Error: Method does not exist or incorrect signature: [LIST:System.SelectOption].keySet() at line 7 column 26
Thanks
Hey..I am able to solve it thanks for ur help it helped me a lot to solve my problem.I went through many docs for this ..but got it from ur side at the end..thanks for ur help, thanks a lot.
I do have another question for u do u have any idea on dynamic binding of controls in Vf page from Apex code.
Thanks,
shaan