Activity Forums Salesforce® Discussions How to resolve System in QueryException: unexpected token: ',' message in Salesforce?

  • Aditya

    Member
    January 20, 2020 at 2:23 pm

    Try this.......... By using BackSlash  ''

    public class ContactSearch {

    public static list<contact> searchForContacts(string lastname ,string mailingCode)
    {
    String query = 'select id, name from contact where lastname ='' +lastname+ '' and MailingPostalCode = ''+mailingCode+''';
    Contact[] myContacts = Database.query(query);
    system.debug(myContacts);
    return myContacts;

    }

    }

  • Charan

    Member
    August 4, 2020 at 5:18 pm

    Sumit,Please try removing comma (,) and replace it with AND operations as below.
    String query = 'SELECT id, name FROM contact WHERE LastName =:lastname AND MailingPostalCode = :mailingCode';

    • This reply was modified 4 years, 4 months ago by  Charan.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos