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
Vianney Bancillon 8Vianney Bancillon 8 

System.QueryException: line 1:105 no viable alternative at character '"'(double quote)

Hello everyone,
I'm unable to execute this Batch test successfully.
I'm facing the following error ;:

Date de début30/11/2017 18:18
ClassebatchTaskRayTaskUpdateTest
Nom de méthodebatchTaskRayTaskUpdateTest
Réussite/ÉchecFail
Message d'erreurSystem.QueryException: line 1:105 no viable alternative at character '"'
Trace de pileClass.batchTaskRayTaskUpdate.start: line 4, column 1

I don't see any double quote at line 4!
I tried to delete and retype all of single quote, as said in existing posts but it does not solve the issue.

Here is the code:
@isTest(seeAllData=false)
public class batchTaskRayTaskUpdateTest {
    static testmethod void batchTaskRayTaskUpdateTest(){
    Test.startTest();
        TASKRAY__Project__c TRP1 = new TASKRAY__Project__c();
        TRP1.Name ='PlanningVianney';
        TRP1.RecordTypeId = '012b0000000UZYp';
        insert TRP1;
        
        Date oppDate = Date.newInstance(2018,01,8);        
        Opportunity Opp1 = new Opportunity();
        Opp1.Name ='OppVianneyTst';
        Opp1.StageName ='Devis en cours';
        Opp1.CloseDate=oppDate;
        insert Opp1;
                       
        TASKRAY__Project_Task__c taskR1= new TASKRAY__Project_Task__c();
        TASKRAY__Project_Task__c taskR2= new TASKRAY__Project_Task__c();
        TASKRAY__Project_Task__c taskR3= new TASKRAY__Project_Task__c();       
        
        
        
        Date taskRayDate = Date.newInstance(2017,12,6);
                
        taskR1.Name='testTask1';        
        taskR2.Name='testTask2';
        taskR3.Name='testTask3';
        taskR1.TASKRAY__Deadline__c = taskRayDate;
        taskR2.TASKRAY__Deadline__c = taskRayDate;
        taskR3.TASKRAY__Deadline__c = taskRayDate;
        taskR2.RecordTypeID = '012b0000000UZUs';
        taskR3.RecordTypeId = '012b0000000UZUs';
        taskR1.RecordTypeId = '012b0000000UZUs';
        
        taskR1.TASKRAY__Project__c = TRP1.Id;
        taskR2.TASKRAY__Project__c = TRP1.Id;
        taskR3.TASKRAY__Project__c = TRP1.Id;
       
        taskR1.Opportunity__c = Opp1.Id;
        taskR2.Opportunity__c = Opp1.Id;
        taskR3.Opportunity__c = Opp1.Id;
        
        List<TASKRAY__Project_Task__c> taskRList = new List<TASKRAY__Project_Task__c>();
        taskRList.add(taskR1);
        taskRList.add(taskR2);
        taskRList.add(taskR3);
        insert taskRList;
              
               
        batchTaskRayTaskUpdate b = new batchTaskRayTaskUpdate();
        database.executeBatch(b);
        TASKRAY__Project_Task__c newTaskR1 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[0].Id];
        TASKRAY__Project_Task__c newTaskR2 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[1].Id];
        TASKRAY__Project_Task__c newTaskR3 =[SELECT Name, TASKRAY__Project__c, TASKRAY__Deadline__c from TASKRAY__Project_Task__c where Id=:taskRList[2].Id];
        
        
        
    Test.stopTest();
    } 
}
Thanks for the help!

Vianney

 
Best Answer chosen by Vianney Bancillon 8
Leonardi KohLeonardi Koh
Hi Vianney,

You might want to check the actual class your test class is testing, what you are showing here is a test class called batchTaskRayTaskUpdateTest that is attempting to test the class called batchTaskRayTaskUpdate

the problem reported was on the class being tested rather than the test class so you might want to check that and not just the test class.

All Answers

Leonardi KohLeonardi Koh
Hi Vianney,

You might want to check the actual class your test class is testing, what you are showing here is a test class called batchTaskRayTaskUpdateTest that is attempting to test the class called batchTaskRayTaskUpdate

the problem reported was on the class being tested rather than the test class so you might want to check that and not just the test class.
This was selected as the best answer
Vianney Bancillon 8Vianney Bancillon 8
Awesome! Thanks Leonardi!
You're right: I had to check my batchTaskRayTaskUpdate. I have replaced my double quote by single quote.
Unfortunately, I have another compilation error:
Error: Erreur de compilation : Missing ';' at 'impératif' à la ligne 3 colonne 131
I don't understand why I have to add ' ; ' character...

Thanks for your help!
global class batchTaskRayTaskUpdate implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query='Select Name, TASKRAY__Deadline__c,TASKRAY__List__c from TASKRAY__Project_Task__c where TASKRAY__List__c !='impératif'';
        return Database.getQueryLocator(query); 
    }
    
    global void execute(Database.BatchableContext BC,List<TASKRAY__Project_Task__c> scope){
       List<TASKRAY__Project_Task__c> taskRayToUpdate = new List<TASKRAY__Project_Task__c>();
        for(TASKRAY__Project_Task__c t : scope){
            
                taskRayToUpdate.add(t);
            
        }
        update taskRayToUpdate;
    }
    
    global void finish(Database.BatchableContext BC){
        
    }
}

 
Leonardi KohLeonardi Koh
that's because Salesforce gets confused by the last part of that SOQL string query

'Select Name, TASKRAY__Deadline__c,TASKRAY__List__c from TASKRAY__Project_Task__c where TASKRAY__List__c !='impératif'';

as you can probably guess, the single quote tells Salesforce the start and end of the string... but it is also being used to indicate the string 'imperatif' that you used in the query string to compare against TASKRAY__List__c so what Salesforce ended up seeing instead is

a line saying
'Select Name, TASKRAY__Deadline__c,TASKRAY__List__c from TASKRAY__Project_Task__c where TASKRAY__List__c !='

and thus Salesforce thinks that your query string ended there and missing a semi colon, it did not realize that you did not intend to end your query string there.

you'll have to escape the single quote you use within the SOQL query string so Salesforce understands that they were not intended to terminate the query string..

try
'Select Name, TASKRAY__Deadline__c,TASKRAY__List__c from TASKRAY__Project_Task__c where TASKRAY__List__c !=\'impératif\'';
Vianney Bancillon 8Vianney Bancillon 8
I had tried to escape but my '\' were not in the right position... you indicate me the right syntax.
Thanks a lot Leonardi for your quick answer.
I do not wish to try your patience but I have another problem: 

Erreur de compilation : Cette classe planifiable contient des tâches en attente ou en cours à la ligne -1 colonne -1

I have already sheduled my class. It appears in Apex Batch Jobs, but I don't know how to suspend it, in order to save my batch Class.
 
Vianney Bancillon 8Vianney Bancillon 8
The problem is that I can't see any button or link in the column named "Action" (cf screenshot)apex task manager
Leonardi KohLeonardi Koh
You should check the Scheduled Jobs instead of Apex Jobs, it should have the schedule for the next run time of the Batch Job which would need to be terminated in order to save the batch class. Don't forget to reschedule them again once the changes are saved so the job is put back into the cycle.

What you would see in the Apex Jobs are the details of the job if it was still running... or more likely, the ones that have already passed hence why there's no action available there... because they were already executed and completed or terminated in the past and thus nothing else can be done with them. Whereas the Scheduled Jobs would also show you the job that will be executed in the future which you will need to stop in order to save the changes to the relevant file.
Vianney Bancillon 8Vianney Bancillon 8
Thanks a lot Leonardi, it's all clear to me now and my code runs perfectly!