You need to sign in to do that
Don't have an account?
gastonien
trigger doesn't work in bulk
trigger avgofresiduals on child__c (after insert, after update, after delete,after undelete) { //Set<ID> ids = Trigger.newMap.keySet(); Set<Id> AcctIds = new Set<Id>(); //Set<Id> AcctIds = Trigger.newMap.keySet(); List<child__c > ConList = new List<child__c >(); if(trigger.isInsert || trigger.isUPdate) { for(child__c Con : trigger.New) { AcctIds.add(Con.Deal__c); } } if(trigger.isDelete || trigger.isUndelete) { for(child__c Con : trigger.Old) { AcctIds.add(Con.Deal__c); } } Map<Id, List<child__c >> AcctContactList = new Map<Id, List<child__c >>(); ConList = [SELECT Id, Deal__c, Volume__c, FROM child__c WHERE Deal__c IN : AcctIds ORDER BY CreatedDate DESC LIMIT 3 ]; List<deal__c> AcctList = new List<deal__c>(); double j=0; for(child__c Con : ConList) { if(con.Volume__c!= null) { j += con.Volume__c; } } AcctList = [SELECT volumesum FROM deal__c WHERE Id IN : AcctIds ]; List<child__c > ContList = new List<child__c >(); ContList = AcctContactList.get(Acc.Id); Acc.volumesum = j; } update AcctList; }
All Answers
Thanks for sharing the details. Will you please let us know what error you are getting?
Thanks,
Pratik
1) why are using LIMIT 3 on your SOQL to get conList
2)I did not see where you have defined Acc and where you are populating AcctContactList
sorry just added acc, limit 3 because I want to get only the last 3 records
do you want to get only 3 records or 3 records for each deal.?
i think you are looking for 3 records for each deal.
you should write your SOQL(parent-child relationship query) something like below and process it.
SELECT volumesum, (SELECT Id, Deal__c, Volume__c, FROM childs__c ORDER BY CreatedDate DESC LIMIT 3) FROM deal__c WHERE Id IN : AcctIds ]
there is another trigger on this object(a before trigger) that create the childs and links it to the parent, any idea on how to fix this one so it work on insert?( create child , link to parent and then sum) is it a way to fire a trigger after like an hour or so? because this trigger works fine in an update