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
LionLion 

Reg: Picklist & custom objects. (VFCODE)

Hi,

 

I have 10 custom objects.

 

I would like to retrieve all my custom objects into a picklist using Apex code...

 

 

Please suggest me.

 

 

 

Thanks & Regards:

 

 

 

 

 

kruti tandelkruti tandel

hi, 

 

if you want to fetch all the Object into the picklist. here code is given

 

 

//**********Page**********//
<apex:pageblocksection >

         <apex:selectList value="{!selectedObject}" size="1" id="selobj"  >

            <apex:selectOptions value="{!objectNames}"/>

         </apex:selectList>

      </apex:pageblocksection>

//*********** controller********//

public class AllObjectFetch{

        private Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
       
        public List <SelectOption> objectNames {get;set;}
        public String selectedObject {get; set;}
      
	   public AllObjectFetch() {

	   objectNames = initObjNames();

	}

  private List<SelectOption> initObjNames(){
        List<SelectOption> objNames =  new List<SelectOption>();
        List<String> AllFields = new List<String>(schemaMap.keySet());
        AllFields.sort();
        for(String name : AllFields)
            objNames.add(new SelectOption(name,name));
        return objNames;
    }
}