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
RaghubmRaghubm 

String.escapesinglequotes giving error 'no viable alternative at character '\''

Tryring to execute a query byt getting the error 'no viable alternative at character '\' in soql'  

String NSP = 'vlocity_cmt__';

String matrixRowQuery = 'SELECT Id, Name, ' + NSP + 'InputData__c, ' +
            NSP + 'CalculationMatrixVersionId_r.' + NSP + 'Priority_c, ' +
            NSP + 'CalculationMatrixVersionId_r.' + NSP + 'VersionNumber_c ' +
            'FROM ' + NSP + 'CalculationMatrixRow__c WHERE ' +
            NSP + 'CalculationMatrixVersionId__c = \'' + matrixVersion.Id + '\' AND Name != \'Header\'';

matrixRowQuery = String.escapeSingleQuotes(matrixRowQuery);
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

Can you check the similar question posted in stack exchange.

https://salesforce.stackexchange.com/questions/130238/no-viable-alternative-at-character

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Shri RajShri Raj
Try removing the backslash and the String.escapeSingleQuotes() method from the query,
String matrixRowQuery = 'SELECT Id, Name, ' + NSP + 'InputData__c, ' + NSP + 'CalculationMatrixVersionId_r.' + NSP + 'Priority_c, ' + NSP + 'CalculationMatrixVersionId_r.' + NSP + 'VersionNumber_c ' + 'FROM ' + NSP + 'CalculationMatrixRow__c WHERE ' + NSP + 'CalculationMatrixVersionId__c = '' + matrixVersion.Id + '' AND Name != 'Header'';
and see if that resolves the issue.