+ Start a Discussion
Swamy PSwamy P 

Dynamic Apex

Hi

I am retriving all sobjects in a pageblocktable by DynamicApex,but am not able to display all object names in pbtable column.iwant to display the object names in PBTable.

how,we can achieve this?

V.f:

<apex:page controller="allobjects_in_pbtable">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!objects}" var="a">
                <apex:column />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Class:

public class allobjects_in_pbtable {

    public list<Schema.SObjectType> getObjects() {
    Map<String,Schema.SObjectType> gd=schema.getGlobalDescribe();
        list<Schema.SObjectType> ss=gd.values();
        return ss;
    }

}

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Make the followed change in the page markup.

 

<apex:page controller="allobjects_in_pbtable">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!objects}" var="a">
                <apex:column value="{!a}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

  You missed the value attribute in Column component. So the Object name was not displayed in the page.

All Answers

SurekaSureka

Hi,

 

Change the return type of the method from "list<Schema.SObjectType>" to List<String>"

 

Return gd.Keyset(). You can get the list of Object names.

 

Thanks

Abhi_TripathiAbhi_Tripathi

heyy...try this..it can help you..

 


 Public List<SelectOption> getName() {
  
            
        //Declaring the list  
         List<SelectOption> Options = new List<selectOption>();
         
        //Method for retreiving all sObject
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
  
  //Loop for a map      
  for(Schema.SObjectType f : gd.Values()){
    options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getLabel()));
      }
    return options;
  }
harsha__charsha__c

Make the followed change in the page markup.

 

<apex:page controller="allobjects_in_pbtable">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!objects}" var="a">
                <apex:column value="{!a}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

  You missed the value attribute in Column component. So the Object name was not displayed in the page.

This was selected as the best answer
Swamy PSwamy P

Hi surekha

                  u r saying that replace "list<Schema.SObjectType>" to List<String>",but am getting an error i.e

     Illegal assignment from SET<String> to LIST<String>....So that i can change list to SET again it shows an error i.e

           SetValue.name .....once check it.i thought that error by v.f only....

 

 v.f  Code:<apex:page controller="allobjects_in_pbtable">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!objects}" var="a">
                <apex:column value="{!a.name}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

class:

public class allobjects_in_pbtable {
    public set<string> getObjects() {
    Map<String,Schema.SObjectType> gd=schema.getGlobalDescribe();
       set<string> ss=gd.keyset();
        return ss;
    }

}

harsha__charsha__c

 set<string> ss=gd.keyset();


Change this to followed

 

 set<string> ss = new  set<string>();

ss.addAll(gd.keyset());

Swamy PSwamy P

Hi Harsha,

                 u'r suggestion is clearing my doubt and one more thing is that i want to display in an alphabetical order

so,i try to sort out them..but it shows an error i.e,

System.ListException: One or more of the items in this list is not Comparable.

code:

 

public list<Schema.SObjectType> getCusobjs() {
       list<Schema.SObjectType> sltd=new list<Schema.SObjectType>();
        Map<String,Schema.SObjectType> gd=schema.getGlobalDescribe();
        list<Schema.SObjectType> ss=gd.values();
        for(Schema.SObjectType s:ss){
            if(s.getDescribe().getName().contains('__c')){
                sltd.add(s);
                // sltd.sort();
            }
        }
        return sltd;
    }

harsha__charsha__c

For this I think that you need to add these list values to a list of string and then you can sort.