When I run the following query in query editor I get this error.


Unknown error parsing query


SELECT Id, OwnerId,Account.OwnerId
FROM Contact where OwnerId = Account.OwnerId limit 100

Does anybody know what the problem is?

| improve this question | | | | |

You can't compare a field to another field in SOQL. Take a look at the documentation on fieldExpression Syntax (emphasis mine):

fieldName comparisonOperator value

value: A value used to compare with the value in fieldName. You must supply a value whose data type matches the field type of the specified field. You must supply a native value—other field names or calculations are not permitted. If quotes are required (for example, they are not for dates and numbers), use single quotes. Double quotes result in an error.

A common workaround is to create a checkbox formula to the same effect. Then just check if it's true in your query.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.