You need to sign in to do that
Don't have an account?

System.SObjectException in rollUp summary for sum
Hi developers,
Please fix th issue for this
set<id> idSet = new set<id>();
List<Child__c> cList = new List<Child__c>();
List<Parent__c> pList = new List<Parent__c>();
if(trigger.isinsert ||trigger.isupdate ||trigger.isundelete){
for(Child__c c : trigger.new){
if(c.ParentMD__c != null)
idSet.add(c.ParentMD__c);
}
}
if(trigger.isdelete){
for(Child__c c : trigger.old){
if(c.ParentMD__c != null)
idSet.add(c.ParentMD__c);
}
}
if(idSet.size()>0){
decimal amt = 0;
cList = [Select id, ParentMD__c from Child__c where ParentMD__c in: idSet];
Map<id,List<Child__c>> prMap = new Map<id,List<Child__c>>();
for(Child__c c : cList){
prMap.put(c.ParentMD__c, new List<Child__c>());
prMap.get(c.ParentMD__c).add(c);
}
pList = [Select id,TotalAmt__c from Parent__c where id in: prMap.keySet()];
for(Parent__c p : pList){
for(Child__c ch : prMap.get(p.id)){
if(ch.MyAmt__c != null)
amt += ch.MyAmt__c;
}
p.TotalAmt__c = amt;
}
update pList;
}
}
Add the MyAmt__c in the query on the child object.
i.e. the new query is like:
cList = [Select id, ParentMD__c, MyAmt__c from Child__c where ParentMD__c in: idSet];
Let me know if it helps you.
Many Thanks,
Sunil Rathore
Thank you for help, now its working, but it is not performing sum,
i created 4 child rec, but it is updating only one, can u overlook a code again..
https://blog.jeffdouglas.com/2009/07/30/roll-up-summary-fields-with-lookup-relationships-part-1/
https://medium.com/@palanic/roll-up-summary-from-child-account-to-patent-account-d0d97114e883
Replace this code
with the following code: Let me know if it helps you out.
Many Thanks,
Sunil Rathore