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
coolcool 

need help: Pass parameters to query

Dear all,
I want to pass parameters(sobject name.queryfield) entered through input fields to the query.
i ttried the following code. But it's not working. error given is: Save error: unexpected token: :

public class ComponentController2 {
   ComponentController2 comCon; 
Opportunity opportunity;
OpportunityContactRole[] oppContactRole;
String oppContactName;
OpportunityContactRole contactRole;
String sobjectName;
String queryfield;

 public opportunity getOpportunity() {
        return opportunity;
    } 
   
    public OpportunityContactRole[] getoppContactRole() {         
        return oppContactRole;
    }

public List<SelectOption> getItems() {
//    String queryString=' select ' + queryfield + ' from'+ sobjectName +'WHERE OpportunityId= :ApexPages.currentPage().getParameters().get(\'id\')' ;
//    if(sobjectName=='OpportunityContactRole'){
//    this.oppContactRole=[queryString];
   // this.oppContactRole = Database.query(queryString);
    //}
   
       try{
            this.oppContactRole = [SELECT :comCon.queryfield FROM OpportunityContactRole
            WHERE
            OpportunityId= :ApexPages.currentPage().getParameters().get('id') ORDER BY IsPrimary DESC, CreatedDate ASC LIMIT 3];           
        }catch (QueryException e){
        }
          
List<SelectOption> options = new List<SelectOption>();
for(OpportunityContactRole con:oppContactRole){
    //String  s='';
    //if(queryfield=='Name')
String s=con.Contact.Name;
options.add(new SelectOption(con.Id,s));
}
return options;
}


public void setSobjectName(String sobjectName){
this.sobjectName=sobjectName;
}

public String getSobjectName(){
return sobjectName;
}

public void setQueryfield(String queryfield){
this.queryfield=queryfield;
}

public String getQueryfield(){
return queryfield;
}

public String getoppContactName() {
return oppContactName;
}

public void setoppContactName(String oppContactName) {
this.oppContactName = oppContactName;
}

}

pls help me to solve this problem.

Thanks in advance!

Cool!
Ron HessRon Hess
you cannot use ':' in any part of the SOQL except the where clause

Message Edited by Ron Hess on 08-19-2008 08:55 AM