function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Malformed Query

Can you tell me what is wrong with this query?

select email, firstName from Contact where email = '' or email = '' or email = '' or email = '' and FirstName = 'Sean' or FirstName = 'Jack' or FirstName = 'Frederico' or FirstName = 'Rose'

I am using the partner wsdl to access the API, and this query throws a malformed query exception every time. I have tried with all combinations of upper and lower case for the field and table names.

Hi Nikki,

The where clause in your SOQL statement is ambiguous as to the precedence of the logical operators as you have constructed.  Accepted coding standards and styles aside, for SOQL statements, you need to provide hints to the SOQL parser as to what the precedence of your logical operators are by using parenthesis like this

where (email = '' or email = '' or email = '' or email = '') and (FirstName = 'Sean' or FirstName = 'Jack' or FirstName = 'Frederico' or FirstName = 'Rose')

This removes the ambiguity in your original construct as to what order to evaluate the expressions that otherwise are difficult, if not imposssible, to determine.