You need to sign in to do that
Don't have an account?
Mike_M
Why does this not work. (Simple code question)
Hi, I am working through the totorial and came to the part for triggers. Below is the code straight from the tutorial PLUS one extra line that I added shown in red.
trigger HandleProductPriceChange on Merchandise__c (after update) {
List<Line_Item__c> openLineItems =
[SELECT j.Unite_Price__c, j.Merchandise__r.Price__c
FROM Line_Item__c j
WHERE j.Invoice_Statement__r.Status__c = 'Negotiating'
AND j.Unite_Price__c < j.Merchandise__r.Price__c
AND j.Merchandise__r.id IN :Trigger.new
FOR UPDATE];
for (Line_Item__c li: openLineItems) {
if ( li.Merchandise__r.Price__c < li.Unite_Price__c ){
li.Unite_Price__c = li.Merchandise__r.Price__c;
}
}
update openLineItems;
}
When I try to SAVE I get a compile error on the line I added. [unexpected token: j.Merchandize__r.Price__c]
Why does my new line of code not work?
(Note: Unite_Price really IS the field name. It's a typo that I never went back to fix.)
Thanks,
Mike
To my knowledge, SOQL cannot compare value of two fields within the SOQL statement.
To Accomplish this you could:
All Answers
Typo? In your post:
[unexpected token: j.Merchandize__r.Price__c]
The field appears to be j.Merchandise__r.Price__c
-Andy
Yes, I mis-typed the error message. Sorry about that.
Also, please note that both of the column names in the line I added (in red) are also named in the SELECT list. How can these two columns be understood within the context of the SELECT list, but not within the context of the WHERE clause?
More info:
This compiles ...
To my knowledge, SOQL cannot compare value of two fields within the SOQL statement.
To Accomplish this you could:
Thanks.
See my update post on how to accomplish this with the one soql statement using a map
Cool, thanks again!