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
Vinay RamuVinay Ramu 

Display List<String> in VisualForce Page

Need help in displaying List<String> in VF Page. Even with below code nothing displaying except h1 html text.

VF Page Code:
<apex:page controller="SObjectsListPageController">
    <h1>List Of sObjects</h1>
    <apex:repeat value="{!sObjectsList}" var="listStr" id="theRepeat">
        <apex:outputText value="{!listStr}" id="theValue"/><br/>
    </apex:repeat>
</apex:page>

Controller:
public class SObjectsListPageController {
    public List<String> sObjectsList {get; set;}
    public List<Schema.SObjectType> sObjTypeList = new List<Schema.SObjectType>();

    public void getsObjectsList (){
        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            sObjectsList.add(str);
        }
    }
}

Thanks,
Vinay
Best Answer chosen by Vinay Ramu
Vinay RamuVinay Ramu
Thanks for providing inputs.

Modified VF Page as below:
<apex:page controller="SObjectsListController">
    <apex:form >
        <apex:pageBlock title="List Of Objects">
            <apex:pageblockTable value="{!lstObjects}" var="f">
                <apex:column value="{!f}"><apex:facet name="header">Object Names</apex:facet></apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
Vinay

All Answers

tamilselvan ctamilselvan c
Hi Vinay,

Please find Updated Code. It should work fine now.

Apex Controller:
public class SObjectsListPageController {

    public List<String> getsObjectsList (){
        List<String> finalList=new List<String>();

        List<Schema.SObjectType> sObjTypeList = new List<Schema.SObjectType>();

        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            finalList.add(str);
        }
        return finalList;
    }
}

Regards,
Tamilselvan.
Ajay K DubediAjay K Dubedi
Hi Vinay,

You can use the below code: 
 
public class SObjectsListPageController1 {
    public List<String> sObjectsList {get; set;}
    public SObjectsListPageController1 (){
        sObjectsList = new List<String>();
        List<Schema.SObjectType> sObjTypeList = new List<Schema.SObjectType>();
        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            sObjectsList.add(str);
        }
    }
}
 
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com

 
Vinay RamuVinay Ramu
Thanks for providing inputs.

Modified VF Page as below:
<apex:page controller="SObjectsListController">
    <apex:form >
        <apex:pageBlock title="List Of Objects">
            <apex:pageblockTable value="{!lstObjects}" var="f">
                <apex:column value="{!f}"><apex:facet name="header">Object Names</apex:facet></apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
Vinay
This was selected as the best answer
Vinay RamuVinay Ramu
My Controller:
public class SObjectsListController {
    public List<String> lstObjects {get; set;}
    public SObjectsListController(){
        lstObjects = new List<String>();
        List<Schema.SObjectType> sObjTypeList;
        Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
        sObjTypeList = objMap.values();
        String str;
        for(Schema.SObjectType scs : sObjTypeList){
            str = scs.getDescribe().getName();
            lstObjects.add(str);
//            System.debug(str);
        }
    }
}