You need to sign in to do that
Don't have an account?
NikiG22
Rollup number of Custom Objects
Hello - I have a custom object called a Sectacular__c that is located on the OpportutiyLineItem.
I need to roll up the count of all the Products (opportutniyLineItems) the Spectatular has.
I have gotten the following error but can not figure out the issue:
Error Error: Compile Error: Didn't understand relationship 'OpportunityLineItem' in FROM part of query call. 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 10 column 30
Here is my code:
trigger OppLineItmRollup on Spectacular__c (after insert,after update) { Set<id> RollChilSet = new Set<id>(); List<Spectacular__c> updateList = New List<Spectacular__c>(); for(OpportunityLineItem rollUpchild :trigger.new){ RollChilSet.add(rollUpchild.Spectacular__c); } for(Spectacular__c rolPar:[select id,Sponsorships_Sold__c,Sold_Amount__c,(select id, UnitPrice, Quantity, Spectacular__c FROM OpportunityLineItem) FROM Spectacular__c where id IN:RollChilSet]) { decimal totalval = 0; for(OpportunityLinrItem rol : rolPAr.OpportuntityLineItem){ totalval = totalval + rol.Quantity; } rolPa.Sponsorships_Sold__c = totalval ; updateList.add(rolPar); } update updateList; }
Please help.
Niki
For queries like that you are going to want to use the Child Relationship Name, not the API Name from the custom field detail page on the Opportunity Product object. It should be something along the lines of "Opportununity_Product" etc...
You will then want to add "__r" to the end.
Hope that makes sense...
I have tried OpportuntiyLineItems, OpportunityLineItem__r?
I modified my post above, check it out again.
that worked. but now im getting this error.
Code:
Set<id> RollChilSet = new Set<id>();
List<Spectacular__c> updateList = New List<Spectacular__c>();
for(OpportunityLineItem rollUpchild :trigger.new){
RollChilSet.add(rollUpchild.Spectacular__c);
}
thanks for all your help
Right, because the trigger is on the Spectacular__c object. Trigger.new has references to all the Spectacular__c objects, in that loop you are trying to reference OpportunityLineItems....
sorry APEX is not my strong point.
So i have my Spectacular object that has opportunityLine items associated with it. So sales will sell a Spec and add it to their opportuntiy product. i need the roll up to count everytime a new Spec is added or removed and add the number to the Sponsorships_Sold__c field.
I will also need it to roll up all the UnitPrice (amounts) and add it to the Sold_Amount__c field.
You're going to want the trigger on the Opportunity List Items then. Something like this...
You are also going to want to expand this logic to subtract the values when a record is deleted. Let me know if you have any questions.
Ok - so I have this code. It dosent throw any errors but it isnt adding the number to my Spectacular Object?