can anyone help me to display all the standard objects in one picklist and when i select any one object, then all those fields which are queryable will display as a multi select picklist.
public class ClassName{
public List<SelectOption> objects {get; set;}
public List<SObject> records {get; set;}
public string choosenObject {get; set;}
public ClassName(){
objects = new List<SelectOption>();
records = new List<SObject>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<String> objectList = new List<String>();
objectList.addAll(gd.keyset());
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objectList );
for(Schema.DescribeSobjectResult res : results) {
if( ! res.isCustom())
objects.add(new selectOption(res.getName() ,res.getLabel()));
}
}
public void queryMe(){
if(string.isNotBlank(choosenObject))
records = database.query('select Id, Name from '+choosenObject);
//you may need to remove Name field for some objects
}
}
You can use the Schema class to achieve this.
getGlobalDescribe()
Returns a map of all sObject names (keys) to sObject tokens (values) for the standard and custom objects defined in
Visualforce Page
Apex Class
Please mark this as the best answer if this helps