You need to sign in to do that
Don't have an account?
Kamal Kishore Singh
Self Hierarcky lookup ,Roll Up Summary
Hello Everyone,
I have a challenging requirement for one my project .I want to have a trigger where i need to sum up a field xxx from childs in self lookup .
For Example if A is parent of B and B is parent of C .If value of field xxx changes from x to y in Record C.The sum of field xxx should be calculated for all parents.This is possible if we use recursive trigger .
The challege is to do it in ,one single update.
Has any body done this before.
Regards
I have a challenging requirement for one my project .I want to have a trigger where i need to sum up a field xxx from childs in self lookup .
For Example if A is parent of B and B is parent of C .If value of field xxx changes from x to y in Record C.The sum of field xxx should be calculated for all parents.This is possible if we use recursive trigger .
The challege is to do it in ,one single update.
Has any body done this before.
Regards
Total all children who have B as a parent - update B.
Total all children who have A as a parent - update A.
Is that what you're trying to do?
Yes ,I need to update a field on parent and value should be the sum of a decimal field from all children in self hierarchy,and I need to do it in single update.
Basically - I think you'll want to think in terms of child, parents, and grand parents. You'll want to gather the parent Ids for the children that fired the trigger. Then with those IDs, get and total all of the child for those parents. Keep those totals in a map of <ParentId,Amount>. Then you'll want to get all of the grandparents IDs from the parents. Then get ALL of the parents using the grandparent IDs, building another map of <grandparentId,amount>. With those two maps, get a LIST of accounts and update the Amt__c field.
Make sense? It is a bit of a complicated process.
Run Once technique (useful in triggers)
Create a utilities class/method like this…
Public with sharing class util_utilities {
Public static Boolean alreadyExecuted;
}
Then use like this…
If (util_utilities.alreadyExecuted != true) {
Util_utilities.alreadyExecuted = true;
// Other Code to be executed only once…
Thanks for same.It is a good code to begin with and I have developed on a similar pattern.The problem is how to reach till ultimate parent.
https://github.com/abhinavguptas/Salesforce-Lookup-Rollup-Summaries/blob/master/classes/LREngine.cls
https://github.com/afawcett/declarative-lookup-rollup-summaries
I have the same requirement, do you have the solution for the above question.
Please help!
Thank you.