//Apex class
public string fields{set;get;}
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
//method for fields retrival and storage in picklist
public list<selectoption> getFields(){
String type='Account';
List<SelectOption> options = new List<SelectOption>();
//Creating sObject for dynamic selected object
Schema.SObjectType systemObjectType = gd.get(type);
//Fetching field results
Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
Map<String, Schema.SObjectField> M = r.fields.getMap();
//Code for picklist of fields in
options.add(new SelectOption('None' ,'--None--')) ;
for(Schema.SObjectField fieldAPI : M.values()){
options.add(new SelectOption(fieldAPI.getDescribe().getName() , fieldAPI.getDescribe().getLabel())) ;
}
return options;
}//end of code for retrieving fields dynamically
//vf page
<apex:selectList value="{!Field}" size="1">
<apex:selectOptions value="{!Fields}">
</apex:selectOptions>
</apex:selectList>
No comments:
Post a Comment