+ Start a Discussion
Nagaraju Mogili 33Nagaraju Mogili 33 

how can we write a dynamic soql query for multiple objects, here is my code

public class SearchFilter_ctrl {
  public list<innerclass> innerlist {get;set;} 
  public list<opportunity> opplist {get;set;}
  public opportunity oppp{get;set;}
  public string text {get;set;} 
  public list<opportunity> opplist1 {get;set;}
   public  List<Opportunity> optyList {get;set;}
   
    public SearchFilter_ctrl (){
    optyList  = new List<Opportunity>();
      innerlist = new list<innerclass>();
      opplist = [select id,StageName,name,(select id,ProductCode,UnitPrice,Quantity,PricebookEntry.product2id,PricebookEntry.product2.ProductCode,product2.name from OpportunityLineItems),(select id,Phone,QuoteNumber,Tax,TotalPrice from Quotes) from opportunity];
      
      for(Opportunity o :opplist){
         innerlist .add(new innerclass(o,o.quotes,o.OpportunityLineItems)); 
         
        }
       
    }
    
   
  
   public class innerclass{
     public Opportunity opp {get;set;}
     public list<Product2> prolist {get;set;}
     public list<Quote> quolist {get;set;} 
     public list<QuoteLineItem> quolineitem {get;set;}
     public list<OpportunityLineItem> opplineitems {get;set;}
        
     public innerclass(Opportunity  opps,list<Quote> q,list<OpportunityLineItem> ol )
     {   //list<Product2> pro 
     quolist = new list<quote>();
       opp = opps;
       //prolist = pro;
       //quolist = q;
       for(Quote q1:q)
       {
       Quote Q2= [select id,Phone,QuoteNumber,Tax,TotalPrice,(select id from quotelineitems) from quote where id=:q1.id];   
          quolist.add(q2);  
       }
     
      opplineitems = ol;
     }
   }
   
 
  public void search()
  {
     string searchfield = '%'+text+'%';
  opplist = [select id,StageName,name,(select id,ProductCode,UnitPrice,Quantity,PricebookEntry.product2id,PricebookEntry.product2.ProductCode,product2.name from OpportunityLineItems),(select id,Phone,QuoteNumber,Tax,TotalPrice from Quotes) from opportunity where name like : searchfield ];

  }
}


can anyone help me on this...
Raj VakatiRaj Vakati
If you wanted to search and return  multiple objects, you need to use SOSL instead of SOQL