0

I'm getting an error while filtering the search by OwnerId for Task object.

Following is what i'm doing and it is giving me an error : Error: Compile Error: expecting a semi-colon, found ' and OwnerId in :ownerIds' at line 106 column 142

   public void  queryTasks(){

    String qStr2= searchText;
    Set<Id> ownerIds = new Set<Id>();
    String strnormal = '';
    try{
         mydate = date.parse(qStr2);
    }catch(Exception e)
    { }

    String strDate = '';
    if(mydate != null) {
     // strnormal = String.valueOf(mydate );
      String[] qstr3 = String.valueOf(mydate).split(' ',2); 
      strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
    }else{

       strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
    }

    if (ownerIds != null && ownerIds.size() > 0){

      String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize' and OwnerId in :ownerIds';

     }

        //String qStr ='Select OwnerId,Subject,Status,ActivityDate from Task where \''+strDate +'\' limit ' + QueryLimit + ' offset ' + OffsetSize;
        // String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize;


       System.debug(qStr);

        //  String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+ '%\' Order By ' + sortField;


       tasks = Database.query(qStr);
        //tasks.sort();

     }
3

Missing a + between OffsetSize' and the rest of the statement:

  String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize' and OwnerId in :ownerIds';

It should be

  String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '+strDate+' limit ' + QueryLimit + ' offset ' + OffsetSize + ' and OwnerId in :ownerIds';
3
  • Just want to cross check that i'm mentioning my IF condition for OwnerId after ELSE part of date . This is because i'm getting error for qStr not defined whereas i've already defined .
    – JJoseph
    Jul 25 '14 at 13:40
  • @james, yeah thats because you create it with the if() and the try to access it outside the if()....if you declare a variable within an if, you can't access it outside. Read this en.wikipedia.org/wiki/Scope_(computer_science) and then do 50 pushups :) Jul 25 '14 at 13:50
  • 1
    i'd already mentioned that in If but still the same. Anyways,good learning from you.
    – JJoseph
    Jul 25 '14 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.