1

I get the following error in Developer Console (logs) while executing this batch class with the following code snippet.

20:07:09:029 FATAL_ERROR System.QueryException: expecting a colon, found '('

global Database.QueryLocator start(Database.BatchableContext BC) {

    final String query = 'SELECT Id,Name,MedConnect__Submission_Status__c FROM MedConnect__FDA_3500A_MedWatch_Report__c WHERE MedConnect__Submission_Status__c IN (\'Submitted\', \'Transmitted\', \'Ack1\', \'Ack2\') AND MedConnect__Report_Status__c NOT IN (\'Complete\')';
    return Database.getQueryLocator(query);
}

The above example use !=. Same error is received when using <> parameter.

However, the error goes away when I use NOT IN parameter. Can someone please explain what is going on here?


The code which errors out during anonymous execution is:

final String query = 'SELECT Id,Name,MedConnect__Submission_Status__c FROM MedConnect__FDA_3500A_MedWatch_Report__c WHERE MedConnect__Submission_Status__c IN (\'Submitted\', \'Transmitted\', \'Ack1\', \'Ack2\') AND MedConnect__Report_Status__c != (\'Complete\')';
return Database.getQueryLocator(query);
7

If you want to use a not equals operator on a text field, you must use a single, quote wrapped value. Parentheses indicate a collection and will only work with IN or NOT IN operators.

A single value would look as follows:

String soql = 'SELECT ... FROM ... WHERE Field__c != \'Single Value\''
0

The following code worked.

global Database.QueryLocator start(Database.BatchableContext BC)
{

    final String query = 'SELECT Id,Name,MedConnect__Submission_Status__c FROM MedConnect__FDA_3500A_MedWatch_Report__c WHERE MedConnect__Submission_Status__c IN (\'Submitted\', \'Transmitted\', \'Ack1\', \'Ack2\') AND MedConnect__Report_Status__c != \'Complete\'';
            return Database.getQueryLocator(query);
}re

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.