Symptom
- Error: 'MALFORMED_QUERY'
- SOQL query fails when adding a parameter.
- When hard coding the value in the SOQL query instead of using the parameter, the report refresh successfully.
- When connecting to Salesforce.com in Crystal Reports, and adding a SOQL query with a parameter, it fails with the error:
'Database Connector Error: 'MALFORMED_QUERY: WHERE <value=value.
ERROR at Row:x:Column:y
Bind variables only allowed in Apex code'
- Note: Images and data in this SAP Knowledge Base Article is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.
Environment
- SAP Crystal Reports 2008
- SAP Crystal Reports 2011
- SAP Crystal Reports 2013
- SAP Crystal Reports 2016
- Salesforce.com
Reproducing the Issue
- In Crystal Reports, create a connection to Salesforce.com
- In the "Database Expert", click on "Add Command", and type a SOQL query.
- Create a string parameter, and add it to the WHERE clause of the SOQL Query like:
SELECT AccountNumber, Name
FROM Account
WHERE Name={?MyParameter}
- After clicking 'OK', it prompts for a parameter value. After entering a value, it fails with the error:
'Database Connector Error: 'MALFORMED_QUERY: WHERE <value=value.
ERROR at Row:x:Column:y
Bind variables only allowed in Apex code'
Cause
- Quotations missing around the parameter in the SOQL query to indicate it is a string value, and this is why Saleforce generates an error.
Resolution
- Add single quotes around the parameter name in the WHERE clause of the SOQL query.
For example:
If we have the following SOQL query with the string parameter name: MyParameter in the WHERE clause, it will fail.
SELECT AccountNumber, Name
FROM Account
WHERE Name = {?MyParameter}
To indicate to Salesforce.com the value passed in the parameter is a string, surround the parameter by single quotes, like:
SELECT AccountNumber, Name
FROM Account
WHERE Name = '{?MyParameter}'
You will then be able to successfully refresh the report.
Keywords
CR, SForce , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , Problem
Product
Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports 2013 ; SAP Crystal Reports 2016