MALFORMED_QUERY: meaning and how to fix it

SOQL and queries Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

MALFORMED_QUERY: The query string has invalid SOQL syntax, or exceeds a query limit such as the maximum query length. Start with: Look at the token named in the message and the text right before it.

Typical message: MALFORMED_QUERY: unexpected token: 'FROM'

Cause

The query string has invalid SOQL syntax, or exceeds a query limit such as the maximum query length.

How to fix MALFORMED_QUERY

  1. Look at the token named in the message and the text right before it.
  2. Check commas between fields, quotes around strings and the order SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT.
  3. Test the query in the Developer Console Query Editor.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does MALFORMED_QUERY mean in Salesforce?

The query string has invalid SOQL syntax, or exceeds a query limit such as the maximum query length.

How do I fix MALFORMED_QUERY?

1. Look at the token named in the message and the text right before it. 2. Check commas between fields, quotes around strings and the order SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT. 3. Test the query in the Developer Console Query Editor.

More SOQL and queries errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.