+ Start a Discussion
AnonymouseAnonymouse 

System.QueryException: Unexpected Token: EOF

Hello,

I'm currently getting the following error when I try to test: "System.QueryException: unexpected token: <EOF>".

Class:
global class LeadProcessor implements Database.Batchable<sObject>, Database.Stateful {

    // Use a QueryLocator in the start method to collect all 
    // Lead records in the org
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
        	'SELECT Id, LeadSource' +
            'FROM Lead' //+
//            'WHERE LeadSource = null'
        );
    }
    
    // Execute method must update all Lead records in the org 
    // with the LeadSource value of 'Dreamforce'
    global void execute(Database.BatchableContext bc, List<Lead> leadList) {
        
        // Process each batch of records
        List<Lead> newLeadList = new List<Lead>();
        
        // Check if the list is empty
        if (!leadList.isEmpty()) {
            
            // Add new LeadSource to each Lead
            for (Lead currentLead : leadList) {
            currentLead.LeadSource = 'Dreamforce';
            
            // Add Lead to list to be updated
            newLeadList.add(currentLead);
        	}
        
        	// Update Leads
        	update newLeadList;
        }
        
    }
    
    // Finish method
    global void finish(Database.BatchableContext bc){
        // Do nothing...
    }
}

Test Class:
@isTest 
private class LeadProcessorTest {
	
    @testSetup
    static void setup() {
    
        // Create Lead list
        List<Lead> leads = new List<Lead>();
        
        // Insert 200 leads
        for (Integer i = 0; i < 10; i++) {
            
 			// Lead.Name is polymorphic; it's made up of FirstName,
 			// MiddleName, LastName, and Salutation; use LastName
            leads.add(new Lead(LastName = 'Smith' + i,
                               Company = 'Smith Hardware' + i));
        }
        
        insert leads;
    }
    
    static testmethod void test() {
        Test.startTest();
        	LeadProcessor lpt = new LeadProcessor();
       		Id batchId = Database.executeBatch(lpt);
        Test.stopTest();
        
        // After the testing stops, assert records were 
        // updated properly
        System.assertEquals(10, [SELECT count() 
                                  FROM Lead 
                                  WHERE LeadSource = 'Dreamforce']);
    }
}

May you please assist?

Sincerely,
Jackie
Best Answer chosen by Anonymouse
Raj VakatiRaj Vakati
It is a space issue between LeadSource and from  


Update code
 
global class LeadProcessor implements Database.Batchable<sObject>, Database.Stateful {
    
    // Use a QueryLocator in the start method to collect all 
    // Lead records in the org
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT Id, LeadSource ' +
            'FROM Lead' //+
            //            'WHERE LeadSource = null'
        );
    }
    
    // Execute method must update all Lead records in the org 
    // with the LeadSource value of 'Dreamforce'
    global void execute(Database.BatchableContext bc, List<Lead> leadList) {
        
        // Process each batch of records
        List<Lead> newLeadList = new List<Lead>();
        
        // Check if the list is empty
        if (!leadList.isEmpty()) {
            
            // Add new LeadSource to each Lead
            for (Lead currentLead : leadList) {
                currentLead.LeadSource = 'Dreamforce';
                
                // Add Lead to list to be updated
                newLeadList.add(currentLead);
            }
            
            // Update Leads
            update newLeadList;
        }
        
    }
    
    // Finish method
    global void finish(Database.BatchableContext bc){
        // Do nothing...
    }
}

 

All Answers

Raj VakatiRaj Vakati
It is a space issue between LeadSource and from  


Update code
 
global class LeadProcessor implements Database.Batchable<sObject>, Database.Stateful {
    
    // Use a QueryLocator in the start method to collect all 
    // Lead records in the org
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            'SELECT Id, LeadSource ' +
            'FROM Lead' //+
            //            'WHERE LeadSource = null'
        );
    }
    
    // Execute method must update all Lead records in the org 
    // with the LeadSource value of 'Dreamforce'
    global void execute(Database.BatchableContext bc, List<Lead> leadList) {
        
        // Process each batch of records
        List<Lead> newLeadList = new List<Lead>();
        
        // Check if the list is empty
        if (!leadList.isEmpty()) {
            
            // Add new LeadSource to each Lead
            for (Lead currentLead : leadList) {
                currentLead.LeadSource = 'Dreamforce';
                
                // Add Lead to list to be updated
                newLeadList.add(currentLead);
            }
            
            // Update Leads
            update newLeadList;
        }
        
    }
    
    // Finish method
    global void finish(Database.BatchableContext bc){
        // Do nothing...
    }
}

 
This was selected as the best answer
AnonymouseAnonymouse
Hi Raj,

Thank you very much. It worked beautifully after I added the space in the query. :)

Sincerely,
Jackie