You need to sign in to do that
Don't have an account?
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;
}
}
Make the followed change in the page markup.
You missed the value attribute in Column component. So the Object name was not displayed in the page.
All Answers
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
heyy...try this..it can help you..
Make the followed change in the page markup.
You missed the value attribute in Column component. So the Object name was not displayed in the page.
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;
}
}
set<string> ss=gd.keyset();
Change this to followed
set<string> ss = new set<string>();
ss.addAll(gd.keyset());
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;
}
For this I think that you need to add these list values to a list of string and then you can sort.