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
Aman BishtAman Bisht 

Soql dynamic query every times returns null...need help

Soql dynamic query every times returns and showing exception....
 
public static list<Idea> getData(String status , String item , String search, String off)
    {
      	Integer offset = integer.valueOf(off);
         String srchstr = '%' + search + '%';
         string query =  'SELECT  Id, Title,  Categories , Body,NumComments,CreatedBy.firstname, status, voteTotal from idea where communityid =: zoneId';

         if(item !='All')
        {
             query +=' AND Categories =\'' +item+ '\'';     
         }  
        if(status !='All')
        {        
             query +=' AND Status=\'' +status+'\'' ;
        } 
      if(search != null)
       {
          query += ' AND Title like \'' +srchstr+ '\'';
       }

          query += 'Limit 2 offset' + offset;
        
            System.debug(query);
            return Database.query(query); 
      

     }


System.QueryException: unexpected token: offset4
 
Amit Chaudhary 8Amit Chaudhary 8
Just add one space after offset
public static list<Idea> getData(String status , String item , String search, String off)
    {
      	Integer offset = integer.valueOf(off);
         String srchstr = '%' + search + '%';
         string query =  'SELECT  Id, Title,  Categories , Body,NumComments,CreatedBy.firstname, status, voteTotal from idea where communityid =: zoneId';

         if(item !='All')
        {
             query +=' AND Categories =\'' +item+ '\'';     
         }  
        if(status !='All')
        {        
             query +=' AND Status=\'' +status+'\'' ;
        } 
      if(search != null)
       {
          query += ' AND Title like \'' +srchstr+ '\'';
       }

          query += 'Limit 2 offset ' + offset;
        
            System.debug(query);
            return Database.query(query); 
      

     }
Let us know if this will help you

Thanks
Amit Chaudhary
Anupama SamantroyAnupama Samantroy
Just put a space after offset within quotes.
Aman BishtAman Bisht
Thanks Amit......working now.......
thanks both of u
Amit Chaudhary 8Amit Chaudhary 8
Hi Aman,

Let us know if you need more help on same topic.