function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JayDP123JayDP123 

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?  

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu

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

Jia HuJia Hu
Jia HuJia Hu

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;
}
}

This was selected as the best answer
JayDP123JayDP123

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!