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
pranoti kokas 27pranoti kokas 27 

after update trigger error on merchandise object of warehouse application

HI everyone!

I was writing a after update trigger on merchandise object in Warehouse Application from a workbook.

Error: Compile Error: Didn't understand relationship 'Invoice_Statement__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 3 column 1

Bellow is the trigger code:

trigger HandleProductPriceChange on Merchandise__c (after update) {
List<Line_Item__c> openLineItems =
[SELECT j.Unit_Price__c, j.Merchandise__r.Price__c
FROM Line_Item__c j
WHERE j.Invoice_Statement__r.Status__c = 'Negotiating'
AND j.Merchandise__r.id IN :Trigger.new
FOR UPDATE];
for (Line_Item__c li: openLineItems) {
if ( li.Merchandise__r.Price__c < li.Unit_Price__c ){
li.Unit_Price__c = li.Merchandise__r.Price__c;
}
}
update openLineItems;
}


The code is iterating through the List of line items and Modifying the price.

Can you please guide me to rectify the error?

Thanks in advance!

 
Naval Sharma4Naval Sharma4
Hi Pranoti,

do you have a custom field on the Line Item object that refers to the Invoice Statement object?  Is that field have an API name of Invoice_Statement__c?
Amit Chaudhary 8Amit Chaudhary 8
Please replace __r with __c . Try below code.
trigger HandleProductPriceChange on Merchandise__c (after update) 
{
	
	List<Line_Item__c> openLineItems =	[SELECT j.Unit_Price__c, j.Merchandise__c.Price__c
													FROM Line_Item__c j
													WHERE j.Invoice_Statement__c.Status__c = 'Negotiating'
													AND j.Merchandise__c.id IN :Trigger.new
													FOR UPDATE];
	
		for (Line_Item__c li: openLineItems) 
		{
			if ( li.Merchandise__c.Price__c < li.Unit_Price__c )
			{
				li.Unit_Price__c = li.Merchandise__c.Price__c;
			}
		}
	update openLineItems;
}
Let us know if this will help you