+ Start a Discussion

Visualforce page with a list of standard and custom objects!!!


   I need to build a visualforce page that does the following:

1. It has a controlling  picklist that displays all the custom and standard objects of the org.

2. It has a dependent multi select picklist of all the fields of object selected in controlling picklist mentioned above.


    Please help me with the code.I 've found few examples , but they use sObjects (list) . I don't want to go through that approach. Is there a better way?



Not sure what you're asking: ... "but they use sObjects (list)." I've actually written something like this previously. It goes like this:


<apex:page controller="mycontroller">
	<apex:form id="form">
			<apex:pageBlockSection columns="1">
					<apex:selectList size="1" value="{!currentobject}">
						<apex:selectOptions value="{!objects}"/>
						<apex:actionSupport event="onchange" action="{!loadfields}" reRender="form"/>
					<apex:selectList size="1" value="{!currentfield}">
						<apex:selectOptions value="{!fields}"/>


public class mycontroller {
	public string currentobject { get; set; }
	public string currentfield { get; set; }
	public selectoption[] getobjects() {
		selectoption[] objects = new selectoption[0];
		map<string,schema.sobjecttype> describe = schema.getglobaldescribe();
		for(string objectname:describe.keyset()) {
			objects.add(new selectoption(objectname,describe.get(objectname).getdescribe().getname()));
		return objects;
	public selectoption[] getfields() {
		selectoption[] fields = new selectoption[0];
		map<string,schema.sobjecttype> describe = schema.getglobaldescribe();
		if(describe.containskey(currentobject)) {
			map<string,schema.sobjectfield> fieldmap = describe.get(currentobject).getdescribe().fields.getmap();
			for(string fieldname:fieldmap.keyset()) {
				fields.add(new selectoption(fieldname,fieldmap.get(fieldname).getdescribe().getlabel()));
		return fields;

This is just an example, but it should work out of the box with minimal fuss.


This helped a lot, Thanks a lot for your time and effort. But on seletion of the object in picklist I am geyying this error message given below:

Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.ApexELResolver$VisualforceArrayList.

   Can you please help me with that?


and there is no !loadfields action in class So I replaced it with GetFields method of yours!!!

Thats the reason you are getting this error. Action method functions can only return PageReference, so you would need to write an Action Function. Here is some information to get you started:   https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_controller_setter_methods.htm