+ Start a Discussion
Swamy PSwamy P 

displaying fields in PageBlockTable by Dynamic soql queries

Hi frndz,

                I have a scenario i.e, iam querying a records by Dynamic SOQL with retun type list<sobject>.I want to display thus retrieved fields in a PageBlock Table for that object...How can i acheive this..

Class:

    public PageReference pbrecords() {
    
    List<sobject> recs=Database.query('Select id,Name from '+sobj+' Where Name =:'+name);
        selected_Objrecs =new list<sobject>();
        for(sobject s:recs){
        
            selected_Objrecs.add(s);
        }
        return null;
    }

  public list<sobject> selected_Objrecs { get; set; }

----------------------

V.F:

<apex:pageBlockTable value="{!selected_Objrecs}" var="a">
                  <apex:column value="{!a}" />
    </apex:pageBlockTable>

Santosh KumbarSantosh Kumbar

Try below code:

 

Class:
list<sobject> selected_Objrecs;

public list<sobject> getselected_Objrecs() {

List<sobject> recs=Database.query('Select id,Name from '+sobj+' Where Name =:'+name);
selected_Objrecs =new list<sobject>();
for(sobject s:recs){

selected_Objrecs.add(s);
}
return selected_Objrecs;
}

----------------------
V.F:
<apex:pageBlockTable value="{!selected_Objrecs}" var="a">
<apex:column value="{!a.Id}" />
<apex:column value="{!a.Name}" />
</apex:pageBlockTable>

 

If you are specifying the Column name in Query then Refer same field name in Apex:column also...

 

Regards

Santosh

www.santoshkumbar.com

Swamy PSwamy P

Unknown property 'SObject.name'  This is the error am getting..Once check it out...