Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am receiving the error "Bind variables only allowed in Apex Code [MALFORMED QUERY]" when testing a SOQL statement called from Jitterbit

We are using Jitterbit to query records from Salesforce, but we are running into an issue. In the query condition statement I am comparing two fields from the Salesforce table. When I go to test the query, it gives me the error "Bind variables only allowed in Apex Code [MALFORMED QUERY]".

Here is an example of the query:

SELECT Id FROM Price_Agreement_Item__c WHERE Approved_Date__c > Last_Upload_Date__c

The fields Approved_Date__c and Last_Upload_Date__c are both contained in Salesforce table Price_Agreement_Item__c. How does one create a SOQL statement that conditions the select statement comparing two fields in the table?

Any help is appreciated.

Thank you in advance.

like image 489
NickFranco Avatar asked Jul 25 '14 15:07

NickFranco


People also ask

What is bind variable in Apex?

A bind variable is an Apex variable that you use in a SOQL query. Use bind variables as placeholders for specific values to be provided later. This isn't a new concept. In Object-Oriented Programming for Admins, you learned about using a parameter as a placeholder in a method.

How do I compare two fields in SOQL?

Salesforce does not allow direct field to field comparison in SOQL query. To achieve this you can create a formula field that will compare fields and return a value (such as true or false) which you can use in a WHERE clause.

What is SOQL?

SOQL stands for Salesforce Object Query Language. You can use SOQL to read information stored in your org's database. SOQL is syntactically similar to SQL (Structured Query Language). You can write and execute a SOQL query in Apex code or in the Developer Console's Query Editor.


2 Answers

In addition to what Daniel Ballinger said, the Soap API also does not allow the 'IN' clause in SOQL queries. It's stupid, but then again, that's 95% of Salesforce.

like image 141
abhishekbh Avatar answered Sep 19 '22 00:09

abhishekbh


Another way this can happen is if you copy your query to the command line and run it without escaping the quotes around any string constants.

E.g., this:

curl -X GET https://x.salesforce.com/services/data/v31.0/query?q=SELECT%20COUNT\(\)%20FROM%20YourObj%20WHERE%20field%20!=%20'Good'

Should be this:

curl -X GET https://x.salesforce.com/services/data/v31.0/query?q=SELECT%20COUNT\(\)%20FROM%20YourObj%20WHERE%20field%20!=%20%27Good%27
like image 38
Ed Norris Avatar answered Sep 21 '22 00:09

Ed Norris