You need to sign in to do that
Don't have an account?
hemant rana
Dynamic retrieval of fields of any sobject in vf page..
Map<String, Schema.SObjectField> M = Schema.SObjectType.Account.fields.getMap();
from this we can retrieve all the fields but of account object only but i want retrieve all the fields of any sobject.
I had accessed the sobjects dynamically by this---
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
list<String> fieldlabel=new list<String>();
GlobalDescribeMap.put(fieldlabel,gd);
//Schema.getGlobalDescribe();
for(Schema.SObjectType f : gd)
{
if(f.getDescribe().isCreateable() && (!f.getDescribe().CustomSetting) && (f.getDescribe().keyPrefix!=null ||f.getDescribe().keyPrefix!='') && f.getDescribe().isUpdateable() && f.getDescribe().isQueryable() && f.getDescribe().isAccessible() && f.getDescribe().isUndeletable())
{
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
fieldlabel.add(f.getDescribe().getLabel());
// system.debug('@@@'+fieldlabel);
}
}
return options;
but not able to dynamically retrieve the fields of any sobject .. please help
from this we can retrieve all the fields but of account object only but i want retrieve all the fields of any sobject.
I had accessed the sobjects dynamically by this---
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
list<String> fieldlabel=new list<String>();
GlobalDescribeMap.put(fieldlabel,gd);
//Schema.getGlobalDescribe();
for(Schema.SObjectType f : gd)
{
if(f.getDescribe().isCreateable() && (!f.getDescribe().CustomSetting) && (f.getDescribe().keyPrefix!=null ||f.getDescribe().keyPrefix!='') && f.getDescribe().isUpdateable() && f.getDescribe().isQueryable() && f.getDescribe().isAccessible() && f.getDescribe().isUndeletable())
{
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
fieldlabel.add(f.getDescribe().getLabel());
// system.debug('@@@'+fieldlabel);
}
}
return options;
but not able to dynamically retrieve the fields of any sobject .. please help
like this Map<String, Schema.SObjectField> M = f.getDescribe().fields.getMap();
All Answers
You can call fields on sobject type as highlighted below:
for(Schema.SObjectType f : gd)
{
if(f.getDescribe().isCreateable() && (!f.getDescribe().CustomSetting) && (f.getDescribe().keyPrefix!=null ||f.getDescribe().keyPrefix!='') && f.getDescribe().isUpdateable() && f.getDescribe().isQueryable() && f.getDescribe().isAccessible() && f.getDescribe().isUndeletable())
{
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
fieldlabel.add(f.getDescribe().getLabel());
// system.debug('@@@'+fieldlabel);
Map<String, Schema.SObjectField> M = f.fields.getMap();
}
}
Error: objectList Compile Error: Expression of type Schema.SObjectType has no member named fields at line 30 column 44
like this Map<String, Schema.SObjectField> M = f.getDescribe().fields.getMap();