I'm working on a Salesforce Hybrid mobile application and there I need to perform an SOQL query with some filters. All are working but an IN clause.

selectedWeekList = dynamicQueryData.selectedWeeks.join(", ");
var dynamicQuery = "SELECT Id, Name FROM My_Obj__c WHERE Start_Date__c = THIS_YEAR AND Status__c ='Pending' AND CALENDAR_MONTH(convertTimeZone(Start_Date__c))=1 AND WEEK_IN_MONTH(convertTimeZone(Start_Date__c)) IN :(" + selectedWeekList + ") AND custom_user__c = 'some_id'  ORDER BY Start_DateTime__c";
forcetkClient.query(dynamicQuery, onSuccess, onError);

It's throwing bind variables only allowed in apex code expetion. Found this somewhat similar post but no luck. I tried LaceySnr's suggestion, but still the same error. Any help will be appreciated.


1 Answer 1


You use of a colon means the system is expecting a bind variable, you're correctly putting in parentheses and creating a comma separated list, so removing the colon should do the trick:

// this: 
AND WEEK_IN_MONTH(convertTimeZone(Start_Date__c)) IN :(" + selectedWeekList + ")

// becomes: 
AND WEEK_IN_MONTH(convertTimeZone(Start_Date__c)) IN (" + selectedWeekList + ")

Depending on how your values are represented (i.e. if they're strings), you'll need to surround each item in the list with single quotes as well if they're not already there.

  • Doh! some mistakes are so pathetic ;) Thanks a lot @LaceySnr
    – highfive
    May 23, 2014 at 7:29
  • 1
    A single wrong character is usually the hardest thing to spot :)
    – Matt Lacey
    May 24, 2014 at 2:21
  • Wish I could vote up your comment 1000 times @LaceySnr
    – highfive
    May 24, 2014 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .