You need to sign in to do that
Don't have an account?
Rachel Jones
Roll Up Trigger on Custom Objects
I am trying to create a roll up summary from one custom object to another:
Parent = Jobs (Job__c)
Child = Purchase Orders (Purchase_Order__c)
Roll up result field on jobs = Total_PO_Amount__c
Value to roll up on child object = Purchase_Order_Total__c (this is in itself a roll up summary of another custom object 'PO_Items__c)
I am getting the following error but not sure why?....
'Error: Compile Error: Didn't understand relationship 'Purchase_Order__c' 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 15 column 20'
Parent = Jobs (Job__c)
Child = Purchase Orders (Purchase_Order__c)
Roll up result field on jobs = Total_PO_Amount__c
Value to roll up on child object = Purchase_Order_Total__c (this is in itself a roll up summary of another custom object 'PO_Items__c)
I am getting the following error but not sure why?....
'Error: Compile Error: Didn't understand relationship 'Purchase_Order__c' 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 15 column 20'
trigger RollUpValue on Purchase_Order__c (after insert, after delete, after undelete) { List<id> JobList = new List<id>(); if(Trigger.isInsert || Trigger.isUndelete){ For(Purchase_Order__c PO1 : Trigger.new){ JobList.add(PO1.id); } } if(Trigger.isDelete){ For(Purchase_Order__c PO1 : Trigger.old){ JobList.add(PO1.id); } } List<Job__c> JobUpdateList = new List<Job__c>(); For(Job__c J : [SELECT Total_PO_Amount__c, (SELECT Purchase_Order_Total__c FROM Purchase_Order__c) FROM Job__c WHERE id =: JobList]){ J.Total_PO_Amount__c = J.Purchase_Order_Total__c.size(); JobUpdateList.add(J); } try{ update JobUpdateList ; }Catch(Exception e){ System.debug('Exception :'+e.getMessage()); } }Thanks in advance for any help (help I am not a coder so laymans terms would be helpful! :-)
All Answers
Go to - >Setup->Your Child object->Click the relationship field
There you will get the Child Relationship Name, include the __r in that name and use that in your query
'Error: Compile Error: Invalid field purchase_order_total__c for SObject Job__c at line 16 column 32' The Purchase_Order_Total__c is a roll up summary field on the child object (its is rolling up an amount field from another custom object 'PO Items' which is a child of the child (confusing myself now!). Any further help here would be much appreciated!
Apex trigger RollUpValue caused an unexpected exception, contact your administrator: RollUpValue: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.RollUpValue: line 17, column 1