System.QueryException: unexpected token: ‘s’

System.QueryException: unexpected token: ‘s’

When you face System.QueryException: unexpected token: ‘s’  issue, use String.escapeSingleQuotes() method to avoid this exception.


Sample SOQL:

        String SOQL = ‘SELECT Id, Name, ( SELECT Id, Name FROM Contacts ), CountryLookup__r.Name FROM Account WHERE Name LIKE ‘%’ + String.escapeSingleQuotes(ld.Company) + ‘%’ LIMIT 100′;
        List < Account > = listAccount = Database.query(SOQL);

Leave a Reply