function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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...