You need to sign in to do that
Don't have an account?
Display Related List of Custom Object fields in pick list
Hi,
Can anyone provide an example of creating a picklist of fields within an object.
I have an object call forms that has a field - Mapping_Object__c - within this I am storing the name of a custom object
i need to then for a child record display the field associated with the mapping object within a selectlist as a single select option.
i have found some examples but none that are doing anything like what I need.
I'm guessing in my class i need to query the parent object to get the mapping_object__c - i then need to use that value to get the fieldnames related to the object.
any ideas or examples of how to do this would be appreciated.
cheers
dan
Hi Dan,
Yes..You need to get the Mapping_Object__c first. Then :
In VF Page:
<apex:selectList value="{!selectedLevel2}" size="1" id="sObjectFieldList">
<apex:selectOptions value="{!sObjectFieldLst}"></apex:selectOptions>
</apex:selectList>
and in Class
public string selectedLevel2 {get; set;}
public List<selectOption> sObjectFieldLst {
get {
List<selectOption> options = new List<selectOption>();
if (selectedObject != NULL) // selectedobject is Mapping_Object__c Object API name
{
options.add(new SelectOption('select','select'));
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(selectedObject);
Schema.DescribeSObjectResult typedescription = targetType.getDescribe();
sObjFieldName = typedescription.Fields.getMap().keyset();
for(string sObjField : sObjFieldName )
{
options.add(new SelectOption(sObjField ,sObjField ));
}
}
return options;
}
set;
}
Let me know if it work, worked for me !!
Good Luck..!!
Please mark it as solved if the solution worked as it might help others.
Thanks,
Prashant Tiwari