You need to sign in to do that
Don't have an account?
Chad Ritchie
Aggregate Result Trigger
Hey guys, trying to create trigger to sum up positions(new, existing), and then update total values for the investors. I am using SEI_Investor_Id__c to match positions to investors.
trigger SumPositions on Investor__c (before insert, before update, before delete) {
for (Investor__c record : Trigger.new) {
record.Sum_of_Positions__c = null;
}
for(AggregateResult result: [SELECT SUM(Position__c.Balance__c) Amt, SEI_Investor_Id__c, Id
FROM Position__c Id
WHERE SEI_Investor_Id__c
IN :Trigger.new GROUP BY SEI_Investor_Id__c, Id]) {
Trigger.newMap.get((Id)result.get('Id')).Sum_of_Positions__c = (Decimal)result.get('Amt');
}
}
trigger SumPositions on Investor__c (before insert, before update, before delete) {
for (Investor__c record : Trigger.new) {
record.Sum_of_Positions__c = null;
}
for(AggregateResult result: [SELECT SUM(Position__c.Balance__c) Amt, SEI_Investor_Id__c, Id
FROM Position__c Id
WHERE SEI_Investor_Id__c
IN :Trigger.new GROUP BY SEI_Investor_Id__c, Id]) {
Trigger.newMap.get((Id)result.get('Id')).Sum_of_Positions__c = (Decimal)result.get('Amt');
}
}
All Answers