You need to sign in to do that
Don't have an account?
cool_coding
Unexpected token: OR in batch
Hello friends,
I am writing a batch and in the start method I am having this error "Unexpected token: OR in batch",
in my query. Can anyone please help me
Below is my piece of code. Thanks
The error is here query += ' OR Statut__c = \'Caduque\'';
I am writing a batch and in the start method I am having this error "Unexpected token: OR in batch",
in my query. Can anyone please help me
Below is my piece of code. Thanks
The error is here query += ' OR Statut__c = \'Caduque\'';
global class Batch_EnvoieMailContratPerdu implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC){ String query = null; query = 'SELECT Id'; query += ', Reference_proposition_commerciale__c, Statut__c'; query += ', ContratPerdue__c'; query += ' FROM Contrat__c'; query += ' WHERE ContratPerdue__c = false'; query += ' AND Reference_proposition_commerciale__c != null'; query += ' AND Statut__c = \'Résilié\''; query += ' OR Statut__c = \'Caduque\''; System.debug(query); return Database.getQueryLocator(query); }
When we are using logic operators on same field, we can use parentheses to define the order in which fieldExpressions are evaluated.
Please find below modified code: Please let me know if that helps you.
Best Regards,
BALAJI
All Answers
When we are using logic operators on same field, we can use parentheses to define the order in which fieldExpressions are evaluated.
Please find below modified code: Please let me know if that helps you.
Best Regards,
BALAJI
global class Batch_EnvoieMailContratPerdu implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
query = null;
query = 'SELECT Id';
query += ', Reference_proposition_commerciale__c, Statut__c';
query += ', ContratPerdue__c';
query += ' FROM Contrat__c';
query += ' WHERE ContratPerdue__c = false';
query += ' AND Reference_proposition_commerciale__c != null';
query += ' AND (Statut__c = \'Résilié\'';
query += ' OR Statut__c = \'Caduque\')';
System.debug(query);
return Database.getQueryLocator(query);
conditions must specify in parentheses when we are using multiple operators of different types. However, multiple operators of the same type do not need to be nested.