I am writing a Scheduler Class to send out mass Emails(HTML email template) based on the time I schedule, below is my code
global class pS implements Database.batchable<sObject> , Database.Stateful{
private EmailTemplate emailTemp;
global pS(){
emailTemp = [Select Id From EmailTemplate Where Name = 'SP'];
}
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select Id, Lastname, Firstname, Email From Contact WHERE ((Account.RecordType.Id = \'01239000000Nabc\' AND Account.premier__c = False) OR (RecordType.Id = \'01239000000Ncdd\' AND Account.Status__c = "Processing")) AND Account.Name != "Test" AND Email != null AND HasOptedOutOfEmail = False';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> scope){
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
for(Contact con : scope) {
if(emailTemp != null && con.Email != null && con.Email != '') {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new List<String>{con.Email});
email.setTargetObjectId(con.Id);
email.setTemplateId(emailTemp.Id);
email.setTreatTargetObjectAsRecipient(true);
emails.add(email);
}
Messaging.sendEmail(emails);
}
}
global void finish(Database.BatchableContext BC){
}
}
when I run this class I receive this error
14:46:18:012 FATAL_ERROR System.QueryException: line 1:215 no viable alternative at character '"'
But when I change my "String query" to below I do not receive any error, also I am receiving emails
String query = 'Select Id, Lastname, Firstname, Email From Contact WHERE Account.RecordType.Id = \'01239000000Nabc\' AND Account.premier__c = False
What am I doing wrong and how can I fix it?