Overview
During synchronization, Riva may encounter a MALFORMED_QUERY error when sending a SOQL (Salesforce Object Query Language) query to Salesforce. This error indicates that the query is structurally invalid and is being rejected by Salesforce before any data is returned.
Symptoms
- Sync errors in Riva logs referencing
MALFORMED_QUERY - Users unable to sync one or more modules (e.g., Appointments, Contacts, Emails)
- Automated Riva error notification emails containing
MALFORMED_QUERY - Error occurs every cycle or intermittently for one or more users
Common error message formats include:
Poll Error - MALFORMED_QUERY: Query is requesting too many junction ids; limit is 500 MALFORMED_QUERY: SOQL statements can not be longer than 20000 characters. MALFORMED_QUERY: expecting a right parentheses, found 'OR'
Common Causes
| Cause | Description |
| Query exceeds 20,000 characters | Salesforce enforces a hard limit on SOQL statement length. |
| Junction ID limit exceeded | Salesforce allows a maximum of 500 junction object IDs per query. |
| Special characters in data | Apostrophes or other characters in field values (e.g., names like "O'Sullivan") break the SOQL string. |
| Misconfigured custom settings | Incorrectly formatted values in CRM connection custom keys can produce unbalanced parentheses or unexpected tokens. |
| Dynamic custom filter syntax error | A bug or incorrect filter configuration causes Riva to generate an invalid query, sometimes introduced after an upgrade. |
Resolution
Riva Cloud: For steps that require adding a key, contact the Riva Support Team.
1. Review the Sync Logs
Check the Riva sync logs for the exact SOQL query and the row/column where the failure occurs. This will help identify the specific cause.
For Riva On-Premise, collect the following files and share with Riva Support Team:
\Riva\Logs\— alllog*andcrmex-log*files from the affected time frame\Riva\Configuration\— all*.policyfiles\Riva\Custom\— all files in the Custom folder\Riva\CRM Integration Logs\— folder for the affected user(s)
2. Apply Advanced Option Keys (SOQL Length / Batch Size)
If the error is "SOQL statements can not be longer than 20000 characters", add the following keys to the Salesforce CRM connection:
Key: Crm.Salesforce.SOQLStatementsMaxLength Value: 5000
Key: Salesforce.BatchSize Value: 900
Steps to add keys (Riva On-Premise):
- Launch the Riva application.
- Click Setup in the top left.
- Double-click the Salesforce Connection.
- Click Advanced Options on the left.
- Click Edit Custom Options >.
- Enter the key name and click Add New.
- Enter the value and click Update.
- Repeat for each additional key.
- Click OK and restart the Riva service.
3. Reduce Junction ID Batch Size
If the error is "Query is requesting too many junction ids; limit is 500", add the following key to the Salesforce CRM connection:
Key: !Sync.Crm.GetCrmObjectsByIdsBatchSize Value: 300
This limits the number of IDs processed per query to stay within Salesforce's platform limit.
4. Check for Special Characters in Data
If the error references a specific record (e.g., a contact name or meeting note title), check whether that value contains apostrophes or other SQL-sensitive characters. These can cause the SOQL string to break unexpectedly.
5. Check Custom Settings on the CRM Connection
Review any custom keys that inject values into SOQL queries (e.g., website match overrides, custom filters). Ensure:
- All parentheses are balanced
- String values are properly escaped
- No duplicate or conflicting filter criteria exist
6. Post-Upgrade Issues
If the error appeared after a recent Riva upgrade, it may be caused by a platform bug affecting custom filter parsing. Contact Riva Support Team immediately.
When to Contact Riva Support
Contact the Riva Support Team if:
- The error persists after applying the recommended keys
- The root cause cannot be identified from the logs
- The error appeared after a Riva upgrade
- Multiple users or policies are affected