+ Start a Discussion

Code explanation

Dear All,


Could somone please tell me if the code I have explained is correct and detailed enough?? From reading the description does the code make sense. If you could add to it I would really appreciate.

public List<SelectOption> getObjectValues(){

        List<SelectOption> optionList = new List<SelectOption>();

        optionList.add(new SelectOption('None' ,'None'));

        List<String> entities = new List<String>(schemaMap.keySet());


            for(String eachobj: entities){

                optionList.add(new SelectOption(eachobj ,eachobj));

            }  return optionList;

To get object values a select option method was written. The schema map gets all schema objects. This is then added into the option list. Each object was added where the entities came from the schema map and then all objects came into the option list. Finally the option list was returned to see the objects on the VF page.      










Try below code to get list of object from your org,


<apex:page controller="objectController" >  
    <apex:form >  
        <apex:SelectList value="{!val}" size="1">  
           <apex:selectOptions value="{!Name}"></apex:selectOptions>  


public class objectController{  

   public String val {get;set;}  
   public List<SelectOption> getName()  
     List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();       
     List<SelectOption> options = new List<SelectOption>();  
     for(Schema.SObjectType f : gd)  
        options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));  
     return options;  


Hope this helps :)