function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave ShulmanDave Shulman 

System.QueryException: no viable alternative at character ' '

Have no idea why im getting this error. From what i found on the community people were saying that i could have a weird quote or something, but I replaced all the single quotes and still getting this error.  Does any one know what this might be.

System.QueryException: line 1:94 no viable alternative at character ' '
global class DeleteHalfYearSales implements Database.Batchable <sObject>, Database.Stateful, Schedulable{
    private static final Date eightMonthsAgoBatch = Date.newInstance(,, 1);
    global void execute(SchedulableContext sc){
        DeleteHalfYearSales batch = new DeleteHalfYearSales();
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'SELECT ID FROM Sales_Data__c WHERE Sales_Type__c = \'Actual\' AND Date__c >= ' + eightMonthsAgoBatch + ' ORDER BY Date__c DESC';
        return Database.getQueryLocator(query);
    global void execute(Database.BatchableContext bc, List<Sales_data__c> scope){
        delete scope;    
    global void finish(Database.BatchableContext BC){
		AsyncApexJob a = [SELECT ID, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems FROM AsyncApexJob WHERE ID = :bc.getJobId()];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        List<String> ToAddress = new List<String>();
        mail.setSubject( 'The status of execute batch DeleteHalfYearSales');
        mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems +
            ' batches with ' + a.NumberOfErrors + ' failures.');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        catch(exception e){
            System.debug('>>>error: ' + e.getMessage());
Test Class
public class DeleteHalfYearSalesTest {
    public static void testSetup() {
        List<Account> AccountList = new List<Account> (); 
        List<Sales_Data__c> SDList = new List<Sales_Data__c> (); 
        Account	Distributor = new Account(Name = 'Account Dist Test',
                                        RecordTypeID = '01280000000HeW4AAK');
        	insert Distributor;
        for (Integer a=0; a<5; a++) {
            Account acc = new Account(Name = 'Account ' + a,
                                      Cmpid__c = 'CMP234' + a);
        insert AccountList;
        for (Account ac : AccountList) {
            for (Integer s=0; s<5; s++) {
                Sales_Data__c sd = new Sales_Data__c (End_user__c = ac.Id,
                                                      Distributor__c = Distributor.ID,
                                                      Amount__c = 100,
                                                      Date__c =,
                                                      Product__c = '01tC0000003HEvUIAW');
        insert SDList;
        ID Var = SDList[0].ID;
        DeleteHalfYearSales d = new DeleteHalfYearSales();
        Sales_Data__c Sales = [SELECT ID FROM Sales_Data__c WHERE ID = :Var Limit 1];
        System.assertEquals(null, Sales.Id);
        System.debug('Expected null Actual ' + Sales.Id);

ANUTEJANUTEJ (Salesforce Developers) 
Hi Dave,

As mentioned in the below link:

Can you try checking the best answer in case if this comes in handy can you try marking this as the best answer so that it can be useful to others in the future.