Skip to main content
12 respuestas
  1. 2 ene 2015, 10:25
    Hi Sushma, I have tested this,

     

    <apex:page controller="ClassName">

    <apex:form >

    <apex:selectList value="{!choosenObject}" size="1">

    <apex:selectoptions value="{!objects}"/>

    </apex:selectList>

    <br/>

    <apex:commandbutton value="Query" action="{!queryMe}" rerender="output"/>

    <apex:dataList id="output" value="{!records}" var="r">

    {!r}

    </apex:dataList>

    </apex:form>

    </apex:page>

     

    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

    }

    }

     
0/9000