System.QueryException: unexpected token: 's'

When you face System.QueryException: unexpected token: 's'  issue, use String.escapeSingleQuotes() method to avoid that.

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);

Cheers!!!

No comments:

Post a Comment