1

I am facing an issue with the querylocator line here. My code snippet as below.

global Database.QueryLocator start(Database.BatchableContext BC){
      query = 'select Id,(select Name from Call2_vod__r where Signature_Date_vod__c !=Null and Account_vod__c not in :existMap.keySet() limit 1) from Account';
      return Database.getQueryLocator(query);}

Error: |FATAL_ERROR|System.QueryException: expecting a right parentheses, found '(' Class.Account_chk_batch.start: line 5, column 1

Line5 is return statement here.Can someone please help?

1
  • Not sure whether '(' mark need to be escaped or not
    – highfive
    Commented Sep 3, 2014 at 9:14

1 Answer 1

2

Interestingly it is this code that doesn't run inside developer console. Try a slight change and see if this works for you.

global Database.QueryLocator start(Database.BatchableContext BC){
set<string> keys = existMap.keySet();
      query = 'select Id,(select Name from Call2_vod__r where Signature_Date_vod__c !=Null and Account_vod__c not in :keys limit 1) from Account';
      return Database.getQueryLocator(query);}

I've just replaced the existMap.keySet() in the query to a set with the keys in. Looks like a problem with the query with the () inside.

5
  • 1
    See the "simple bind variables" mention in the Dynamic SOQL documentation for more information on this.
    – Keith C
    Commented Sep 3, 2014 at 9:45
  • Thanks Richard! It's working. But it is taking long time to complete batch run. Will let you know about this.:) Commented Sep 3, 2014 at 10:18
  • I am sorry Richard. It is showing below error. Commented Sep 3, 2014 at 10:18
  • Error:First error: Apex CPU time limit exceeded Commented Sep 3, 2014 at 10:19
  • You'll probably need a where clause on your main select (from Account). Try the query in developer console and see what's returned. Commented Sep 3, 2014 at 10:51

You must log in to answer this question.

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