You need to sign in to do that
Don't have an account?
VSK98
System.QueryException: expecting a colon, found 'sent' Stack Trace Class.WTPAA_sendReminderwagenoticestoemployees.start: line 8, column 1
Hi,
When i am run the test class i am getting this error
System.QueryException: expecting a colon, found 'sent'
Stack Trace Class.WTPAA_sendReminderwagenoticestoemployees.start: line 8, column 1
Here is my test class
@isTest
private class WTPAA_sendReminderwgntoemployees_Test{
Static testmethod void WTPAA_sendReminderwgntoemployees_TestMethod(){
Date td = system.Today();
User u;
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
System.runAs (thisUser) {
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
UserRole r = [SELECT Id FROM UserRole WHERE Name='WCT Admin'];
u = new User(alias = 'sindu1', email='sandvarma1@deloitte.com',
emailencodingkey='UTF-8', lastname='Smith',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
timezonesidkey='America/Chicago',
username='sandvarma1@deloitte.com.wct.prd.onebox');
insert u;
}
recordtype rt=[select id from recordtype where DeveloperName = 'WCT_Employee'];
Contact con=WCT_UtilTestDataCreation.createEmployee(rt.id);
// con.CreatedDate = td;
insert con;
WTPAA_Wage_Notice__c wgn = new WTPAA_Wage_Notice__c();
wgn.WTPAA_Related_To__c = con.id;
wgn.WTPAA_Status__c = 'Sent';
// wgn.WTPAA_Reminder_for_2nd_week__c = ;
// wgn.WTPAA_Reminder_for_3rd_week__c= td.adddays(14) ;
// wgn.WTPAA_Reminder_for_4nd_week__c = td.adddays(21) ;
insert wgn;
EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'WTPAA_Reminder_for_2_weeks' limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(wgn.WTPAA_Related_To__r.id);
mail.setWhatid(wgn.id);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
for(OrgWideEmailAddress owa1 : [select id, Address from OrgWideEmailAddress]) {
if(owa1.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa1 .id);
}
}
// OrgWideEmailAddress owa = [select Id, Address from OrgWideEmailAddress where DisplayName='Deloitte US Offers1' limit 1];
Test.StartTest();
WTPAA_sendReminderwagenoticestoemployees objBatch = new WTPAA_sendReminderwagenoticestoemployees ();
ID batchprocessid = Database.executeBatch(objBatch);
Test.StopTest();
}
}
Here is the my Batch class
global class WTPAA_sendReminderwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
Date d = Date.today();
String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Status__c,WTPAA_Reminder_for_2nd_week__c,WTPAA_Reminder_for_3rd_week__c,WTPAA_Reminder_for_4nd_week__c FROM WTPAA_Wage_Notice__c WHERE (WTPAA_Reminder_for_2nd_week__c = :d OR WTPAA_Reminder_for_3rd_week__c = :d OR WTPAA_Reminder_for_4nd_week__c = :d) AND WTPAA_Status__c = sent ';
//String SOQL = 'SELECT Id,WTPAA_Company_Name__c, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Is_same_Employer_Mailing_Address__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Is_same_Employer_Mailing_Address__c = false';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTPAA_Reminder_for_2_weeks' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
system.debug('size of the list' +wagenotice.size());
system.debug('ID**********' +w.id);
// List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
mail.setWhatid(w.id);
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa .id);
}
}
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
While execute the batch class i didn't get the error ..............Only when i am run the test class i am getting above error
When i am run the test class i am getting this error
System.QueryException: expecting a colon, found 'sent'
Stack Trace Class.WTPAA_sendReminderwagenoticestoemployees.start: line 8, column 1
Here is my test class
@isTest
private class WTPAA_sendReminderwgntoemployees_Test{
Static testmethod void WTPAA_sendReminderwgntoemployees_TestMethod(){
Date td = system.Today();
User u;
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
System.runAs (thisUser) {
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
UserRole r = [SELECT Id FROM UserRole WHERE Name='WCT Admin'];
u = new User(alias = 'sindu1', email='sandvarma1@deloitte.com',
emailencodingkey='UTF-8', lastname='Smith',
languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
timezonesidkey='America/Chicago',
username='sandvarma1@deloitte.com.wct.prd.onebox');
insert u;
}
recordtype rt=[select id from recordtype where DeveloperName = 'WCT_Employee'];
Contact con=WCT_UtilTestDataCreation.createEmployee(rt.id);
// con.CreatedDate = td;
insert con;
WTPAA_Wage_Notice__c wgn = new WTPAA_Wage_Notice__c();
wgn.WTPAA_Related_To__c = con.id;
wgn.WTPAA_Status__c = 'Sent';
// wgn.WTPAA_Reminder_for_2nd_week__c = ;
// wgn.WTPAA_Reminder_for_3rd_week__c= td.adddays(14) ;
// wgn.WTPAA_Reminder_for_4nd_week__c = td.adddays(21) ;
insert wgn;
EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'WTPAA_Reminder_for_2_weeks' limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(wgn.WTPAA_Related_To__r.id);
mail.setWhatid(wgn.id);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
for(OrgWideEmailAddress owa1 : [select id, Address from OrgWideEmailAddress]) {
if(owa1.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa1 .id);
}
}
// OrgWideEmailAddress owa = [select Id, Address from OrgWideEmailAddress where DisplayName='Deloitte US Offers1' limit 1];
Test.StartTest();
WTPAA_sendReminderwagenoticestoemployees objBatch = new WTPAA_sendReminderwagenoticestoemployees ();
ID batchprocessid = Database.executeBatch(objBatch);
Test.StopTest();
}
}
Here is the my Batch class
global class WTPAA_sendReminderwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
Date d = Date.today();
String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Status__c,WTPAA_Reminder_for_2nd_week__c,WTPAA_Reminder_for_3rd_week__c,WTPAA_Reminder_for_4nd_week__c FROM WTPAA_Wage_Notice__c WHERE (WTPAA_Reminder_for_2nd_week__c = :d OR WTPAA_Reminder_for_3rd_week__c = :d OR WTPAA_Reminder_for_4nd_week__c = :d) AND WTPAA_Status__c = sent ';
//String SOQL = 'SELECT Id,WTPAA_Company_Name__c, WTPAA_Employee_Email__c,WTPAA_Related_To__r.id,WTPAA_Is_same_Employer_Mailing_Address__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Is_same_Employer_Mailing_Address__c = false';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTPAA_Reminder_for_2_weeks' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
system.debug('size of the list' +wagenotice.size());
system.debug('ID**********' +w.id);
// List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
mail.setWhatid(w.id);
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('replicastatelabor@gmail.com')) {
mail.setOrgWideEmailAddressId(owa .id);
}
}
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
While execute the batch class i didn't get the error ..............Only when i am run the test class i am getting above error
You need write string constant with ' symbol.
Try this
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex