You need to sign in to do that
Don't have an account?
Somasundaram S 1
how to get sum from child object from parent in lookup relation
I have a reuiqrement i want to have a field in parent record and get the sum of a field from all child record. this is lookup relationship record. how to do in a easy way , please suggest me.
You have to write a trigger in child object and trigger will do the job .
Please check below link where I have added a post for same kind of requirment .Where you need to replace object and field name accordigngly so that it will work for you .
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000UZq8QAG
Let me know incase it solve your problem .
Thanks
Manoj
All Answers
You have to write a trigger in child object and trigger will do the job .
Please check below link where I have added a post for same kind of requirment .Where you need to replace object and field name accordigngly so that it will work for you .
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000UZq8QAG
Let me know incase it solve your problem .
Thanks
Manoj
I will try trigger before that any other easy way to do it like using process builder , if i couldnt get any good suggetsion i will go trigger, if i get process builder i will do in production.
thanks
soma
in your above code orderitem is child record right , where are you getting the id of parent record to update the sum of pieces, could you please advise me.
thanks
soma
Order is the parent object and orderItem is the child object Pices__c is the field in orderItem and Total pices1__c is the field in Order wheer trigger is updating the value .
Let me know incase any !!
Thanks
Manoj
Thanks for your help and patient i modified the code as per my need and i got below error when i update the existing quantity what am i missing pls suggest me
"Apex trigger Totalquanityleft caused an unexpected exception, contact your administrator: Totalquanityleft: execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: a0i0E0000000YDuQAM: Trigger.Totalquanityleft: line 31, column 1"
could you please help me i couldnt get clue for the above error
What is the error you are getting ?
"Apex trigger Totalquanityleft caused an unexpected exception, contact your administrator: Totalquanityleft: execution of AfterUpdate caused by: System.TypeException: Invalid id value for this SObject type: a0i0E0000000YDuQAM: Trigger.Totalquanityleft: line 31, column 1"
ordListToUpdate.add(new Sample_Lot__c (Id=(Id)res.get('id'),Quantity_Left__c=(Double)res.get('can')));
You have problem like Sample_Transaction__c object there will be a look up field to Sample_Lot__c you need to get that field in place Id you are updating Sample_Lot__c with Sample_Transaction__c Id .I think you are clear now .
let me know incase you have issue .
Thanks
Manoj
ordListToUpdate.add(new Sample_Lot__c (Sample_Lot_ID__c=(Sample_Lot_ID__c)res.get('id'),Quantity_Left__c=(Double)res.get('can')));