Trying to transfer an apex query to Javascript. Wondering if binding works in the same manner?

Also is using result.length valid for the if statement?

var accLike = '%' + 'Construction' + '%';
var accId = '0E40040503F023FE';

result = sforce.connection.query('SELECT Id, Name FROM Account WHERE (Id =: accId) OR (Name LIKE :accLike)');

if(result.length > 0){

1 Answer 1


No, that syntax is unique to Apex. In JavaScript, you must be careful to escape any special characters manually. However, in all modern browsers (not IE 11), you can use template strings:

result = sforce.connection.query(`SELECT Id, Name FROM Account WHERE Id = '${accId}' OR Name LIKE '${accLike}'`);

Note the use of backticks (`) to enclose the string, and ${variable} syntax to merge in values. Also note that strings still need to be quoted with apostrophes (" ' ").

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .