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
RimaRima 

How to display SOQL query results

Hi All,

 

Following is my Apex code:

 

Public class SOQLController{
  public String objectName { get {return objectName ;}set{ objectName = value ;}}
  public String zipCode { get { return zipCode ;} set { zipCode=value ; } }     
  public List<sObject> queryResult { get{return queryResult;}set{ queryResult = value ;}}
        
   
    public PageReference query(){
        String zipFieldName ;       
        if( objectName == 'Account' ){
                zipFieldName = 'BillingPostalCode' ;
        }
           
        // create the query string 
        String qryString = 'SELECT Id FROM ' + objectName + ' WHERE ' + objectName + '.' + 
                    zipFieldName + '=' + '\'' + zipCode + '\'' ; 
        // execute the query
        queryResult = Database.query(qryString) ; 
         
       return null;
        }
        }

 Following is my reference link :

 

http://blog.sforce.com/sforce/2008/09/dynamic-soql--.html#comment-6a00d8341cded353ef0120a8f1e8b3970b

 

I am not able to disply retrieved id's when I give value to Zip code and click on query button. Could anyone please let me know how to display query result? Your help is greatly appreciated.

 

Best Answer chosen by Admin (Salesforce Developers) 
RimaRima

Hi,

 

I did figure out how to display results on VF page.

 

<apex:pageBlock title="Retrived Ids">
    <apex:dataList value="{!queryResult}" var="r">
        <apex:outputText value ="{!r.Id}" />
    </apex:dataList>
</apex:pageBlock>