[SalesForce] JAVASCRIPT soql QUERY IN VISUALFORCE PAGE

this is my javascript code in vf page.
'csvExtdIdRecordValues' its a type of array.
i am pushing names in it.

csvExtdIdRecordValues.push(field[key]);

**And here i am facing error:

—————————-**

var leadRec = sforce.connection.query(
    'select id,name from Account where name like (\'' + csvExtdIdRecordValues+ '\')' );

This is the Error is:

faultstring: "MALFORMED_QUERY: ↵name from Account where name like
('CSVimport_1,CSVimport_2,CSVimport_3↵
^↵ERROR at Row:1:Column:44↵Bind variables only allowed in Apex code"

==================================

Even i tired like this also:

var leadRec = sforce.connection.query(
    'select id,name from Account where name = (\'' + csvExtdIdRecordValues+ '\')' );

Same error i got.

Even like this is also i tired but no luck:

var queryResult = sforce.connection.query('Select Name,Id From Account where name LIKE  (\'' + leadRec.join('\',\'') + '\')' );

Guys Could you pls help me out in this

Thanks & regards

Best Answer

You have to use IN instead of LIKE when checking against a collection..

var leadRec = sforce.connection.query(
    'select id,name from Account where name in (\'' + csvExtdIdRecordValues+ '\')' );
Related Topic