5

I have what should be a very simple SOQL query that I get an error thrown on. The two fields in the WHERE clause are both Decimal types.

SELECT Id, Parent_Object__r.Amount__c, Amount__c
FROM Child
WHERE Parent_Object__r.Amount__c = Amount__c

I am getting a MALFORMED QUERY exception thrown for some reason. Does anyone know why this might be?

Thanks

1 Answer 1

10

Unfortunately that query cannot be executed as written in SOQL since SOQL does not allow direct field comparisons. I would recommend adding a checkbox formula field to your object, Parent_Amount_Equals_Amount__c and have that do the comparison, instead. Then your SOQL query could use that field in the where clause.

SELECT Id, Parent_Object__r.Amount__c, Amount__c
FROM Child
WHERE Parent_Amount_Equals_Amount__c = 'TRUE'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .