You need to sign in to do that
Don't have an account?
Alex Valavanis
Roll up child accounts to parent account
Hi, I'm pretty sure this question has been raised a couple of times ( :) ) but would appreciate if someone could give me a step by step quide on how to roll up child accounts to parent accounts.
I do have a roll up on accounts which sums up the amount of closed won opportunities (2015,2016,2017 price etc. etc. ) but how am i going to roll up the accounts to the parent account (Field "Total Net Amount") ?
P.S Apex code is chinese to me :) but willing to try if you give me guidance
I do have a roll up on accounts which sums up the amount of closed won opportunities (2015,2016,2017 price etc. etc. ) but how am i going to roll up the accounts to the parent account (Field "Total Net Amount") ?
P.S Apex code is chinese to me :) but willing to try if you give me guidance
Can you be more specific on your req and the field names. Because what i understood is that you need to sum up the fields like 2015 price,2016 price,2017 price to a custom field named 'total_amount__c' . Then you can use the below trigger. Here instead of the field 'child_amount__c' you can use your fields like 2015 price,2016 price,2017 price.
@Rajat you need to use parentid instead of ParentAccountId
Hope it helps.Let me know if you have any issues.
Regards
Roshni
All Answers
To get the Net total amount, create a field in account.
Then write trigger on account object. I had the same rquirement, and follow the code in below link.
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000I4PsQAK
It worked for me.
Regards,
Roshni
Hi Alex,
@Roshni appreciate your suggestion !!! but it will not hold the sum correctly when child account will delete.
To utilize rollup summary features completely, I will suggest this code : -
Please let me know in case of any help. I am happy to help you :)
Note : - I am not saying that @Roshni code is wrong, but this code which I am suggesting is ideal for your use case.
Thanks
Can you be more specific on your req and the field names. Because what i understood is that you need to sum up the fields like 2015 price,2016 price,2017 price to a custom field named 'total_amount__c' . Then you can use the below trigger. Here instead of the field 'child_amount__c' you can use your fields like 2015 price,2016 price,2017 price.
@Rajat you need to use parentid instead of ParentAccountId
Hope it helps.Let me know if you have any issues.
Regards
Roshni
Hi Roshni,
1. Why do we need to utilize the sums up of amount of closed won opportunities (2015,2016,2017 price) in coding, when It already done with rollup summary standard salesforce features ?
2. ParentAccountId is simply represent the relationship field for account, so whatever the field name will be, It take place.
3. Yes, we can use checkRecursive, what you have suggest.
Rest I am thinking, Nothing is wrong in my suggesting code :)
Note : Every Problems have multiple solution, so @Alex whatever the solution best suit for your use case, GoAhead
Thanks
If you look at the code you can see we are not taking sums of amount of closed won opportunities (2015,2016,2017 price). Its already there in the account object in 3 fields as i said in the comment section. I am taking their sum and putting it into the parent record ie if a parent record have 2 childs i am summing up the individual roll up fields(2015,2016,2017 price) and putting them into the respective total sums for each year in the parent record or you can put the sum of all years in the total_amount__c field.
Thank you
Hi Alex,
If you also want to roll up the sum of Child price (2015,2016,2017) from child account to parent account in addition with ChildAmount ,then please do minor modification in code which you have marked the best answer and it will work for you . Below is code snippet -
Apex class for checkrcursive -
Now everything is good. I would like to say thanks to @Roshni to let me know the other use case, which i was missed.
@Alex, please let me know, in case of any help. I am happy to help you :)
Thanks,
As mentioned fields "2015 Price", "2016 Price", "2017 Price" are roll ups from child accounts closed won opportunities - and i want a rollup in the Parent account of all the "2015 prices", " 2016 prices" etc. etc.
Hi Alex,
Yes, the latest code snippet will work for you, please goAhead with that and let me know ,If you need any help.
Thanks
@Alex, code that i have last updated is based on the requirement that you have mentioned.
Just check it out
@Alex,
:D :D, Please do one work, Unmark my solution and Mark the @Roshni last updatedCode as Best.
I am happy to be able to given you the solution as per your requirement.
Have a nice day !!!
Thanks
Thank you very much !!! If need help, please let me know. I am happy to help you :)