• bbanks1981
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Good Morning,

 

I am new to Apex coding and any help would be appreciated.  I have a customer object orders and opportunity line items are related to an order.  I am trying to write a trigger that will rollup the total price of products on an order.  I get an error on the SOQL query and I cannot figure out why or work it out.  Below is my code.  Thanks in advance.

 

Trigger SumTotalPriceofProductsonOrder on OpportunityLineItem (after delete, after insert, after undelete, 
after update) 
{

	set<id> order_ids = new set<id>();
	
	if(trigger.isInsert || trigger.isupdate || trigger.isundelete)
		{for (opportunitylineitem t : Trigger.new)
			{if( trigger.isinsert || trigger.isundelete)
				{if(t.Order__c != null && t.totalprice > 0)
					{order_ids.add(t.Order__c);
					}
				}
		
			else if (trigger.isupdate)
				{if (trigger.oldmap.get(t.id).Order__c != null)
					order_ids.add(trigger.oldmap.get(t.id).Order__c);
				 if (trigger.newmap.get(t.id).Order__c != null)
				 	order_ids.add(trigger.newmap.get(t.id).Order__c);
				}			
			}
		}
	else if (trigger.isdelete)
		{for(opportunitylineitem t : Trigger.old)
			{if (t.Order__c != null && t.TotalPrice > 0)
				{order_ids.add(t.Order__c);
				}	
			}
		}

	Orders__c[] ord = new Orders__c[]{};
	
	for (Orders__c o : [Select Id, (Select Id, TotalPrice from OpportunityLineItem) From Orders__c where id in :order_ids])
		{
			double totalPrice = 0;
			
			for (OpportunityLineItem t : o.OpportunityLineItem)
				OrderTotalPrice =+ t.totalprice;
				
			o.Total_Price_of_Products__c = ordertotalPrice;
			ord.add(o);
		}
	update ord;
}

 

Good Morning,

 

I am new to Apex coding and any help would be appreciated.  I have a customer object orders and opportunity line items are related to an order.  I am trying to write a trigger that will rollup the total price of products on an order.  I get an error on the SOQL query and I cannot figure out why or work it out.  Below is my code.  Thanks in advance.

 

Trigger SumTotalPriceofProductsonOrder on OpportunityLineItem (after delete, after insert, after undelete, 
after update) 
{

	set<id> order_ids = new set<id>();
	
	if(trigger.isInsert || trigger.isupdate || trigger.isundelete)
		{for (opportunitylineitem t : Trigger.new)
			{if( trigger.isinsert || trigger.isundelete)
				{if(t.Order__c != null && t.totalprice > 0)
					{order_ids.add(t.Order__c);
					}
				}
		
			else if (trigger.isupdate)
				{if (trigger.oldmap.get(t.id).Order__c != null)
					order_ids.add(trigger.oldmap.get(t.id).Order__c);
				 if (trigger.newmap.get(t.id).Order__c != null)
				 	order_ids.add(trigger.newmap.get(t.id).Order__c);
				}			
			}
		}
	else if (trigger.isdelete)
		{for(opportunitylineitem t : Trigger.old)
			{if (t.Order__c != null && t.TotalPrice > 0)
				{order_ids.add(t.Order__c);
				}	
			}
		}

	Orders__c[] ord = new Orders__c[]{};
	
	for (Orders__c o : [Select Id, (Select Id, TotalPrice from OpportunityLineItem) From Orders__c where id in :order_ids])
		{
			double totalPrice = 0;
			
			for (OpportunityLineItem t : o.OpportunityLineItem)
				OrderTotalPrice =+ t.totalprice;
				
			o.Total_Price_of_Products__c = ordertotalPrice;
			ord.add(o);
		}
	update ord;
}