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

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'

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.