You need to sign in to do that
Don't have an account?
JayDP123
List of sObjects on a VisualForce page
Hi, I am a beginner developer looking for some help.
I am having trouble getting a simple list of all sObjects on a visualForce page. I have seen some examples which use SelectOption lists but I would rather have it in a column in a pageblocktable.
I can get the Map<string, schema.sobjecttype> map = schema.getglobaldescribe(); which gives me all of the sObjects
but I don't know how to get that onto my page. Can anyone help? I am really not good with (get; set;) and I figure that is the way to go. Maybe just a little guidance?
Sorry, try this,
<apex:page controller="objectList" >
<apex:pageBlock >
<apex:pageBlockTable value="{!ObjName}" var="item">
<apex:column value="{!item}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
public class objectList{
public List<String> getObjName() {
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<String> ObjName = new List<String>();
for(Schema.SObjectType f : gd)
{
ObjName.add( String.valueOf(f.getDescribe().getLabel()));
}
return ObjName;
}
}
All Answers
http://developer.force.com/cookbook/recipe/retrieve-a-list-of-objects-using-apex
Sorry, try this,
<apex:page controller="objectList" >
<apex:pageBlock >
<apex:pageBlockTable value="{!ObjName}" var="item">
<apex:column value="{!item}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
public class objectList{
public List<String> getObjName() {
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<String> ObjName = new List<String>();
for(Schema.SObjectType f : gd)
{
ObjName.add( String.valueOf(f.getDescribe().getLabel()));
}
return ObjName;
}
}
Awesome Thanks alot!
I was so close! but was missing the correct syntax for ObjName.add( String.valueOf(f.getDescribe().getLabel())); because in the example he uses add(selectoption.. . .)
Thanks again!