• horosh
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I am fairly new to Apex and Force.com in general. I have been going through the Force.com Workbook (the one that comes with Eclipse Force IDE Help File) which has an example Adding Apex Trigger, with the following 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];

}

The problem: The reference  j.Invoice_Statement__r.Status__c don't work. The code code-complete-assist show me j.invoice_Statement__r and I can't see Status__c attribut.
Error: "Save error: Didn't understand relationship 'Unit_Price__c' 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.    Force.com save problem"

Can you help me please? Thank

  • November 05, 2010
  • Like
  • 0

Hello All,

 

I am fairly new to Apex and Force.com in general. I have been going through the Force.com Workbook (the one that comes with Eclipse Force IDE Help File) which has an example Adding Apex Trigger, with the following code:

 

trigger HandleProductPriceChange on Merchandise__c (after undelete) 
{
	// update invoice line items associated with open invoices
	List 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 trigger saves and even shows up on the Web Interface under Triggers for the Merchandise Object. But when I change the price of the item, the line item never updates the amount. 

 

Can anyone tell me what I am missing? Everything else seems to be working like a charm.

 

Thanks,

Pedram