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

HELP! Calculate the Sum of a RelatedList
Hello guys,
I need help here (my Sales guys are killing me softly) and they would require the Sum of all the investment amount .
Now i know normally Roll-up Summary is used for this; but the Custom Object Adviser is not a Master Relationshipship
In the Adviser record view they will like to see the total sum of all investment associated with the RelatedList ManagedFund__c
Please guys; what is the best way to achieve this and how?
Thanks in advance.
You can check my post at
http://boards.developerforce.com/t5/Apex-Code-Development/Rollup-summary-on-Contact/td-p/408625
It is a more comprehensive trigger which handles multiple scenarios.
All Answers
Write a trigger on ManagedFund__c . Like this
create one field on Adviser object. Total_amount__c.
in below code Insted of Adviser i have taken account.
And instead of ManagedFund__c i have taken opportunity.
You can replace and worked out.
trigger AmountTask on Opportunity (after insert,after update){
if(Trigger.isinsert){
Map<id,decimal> acctotal = new Map<id,decimal>();
for(opportunity opp :trigger.new){
if(opp.amount!=null){
if(acctotal.get(opp.accountid)==null){
acctotal.put(opp.accountid,opp.amount);
}
else
{
decimal amt = 0;
amt = acctotal.get(opp.accountid)+opp.amount;
acctotal.put(opp.accountid,amt);
}
}
}
list<account> alist= new list<account>();
list<account> accList = [select total_amount__c from account where id in:acctotal.keyset()];
for(account a:acclist){
a.total_amount__c+=acctotal.get(a.id);
alist.add(a);
}
update alist;
}
}
Hi There,
I think this can be done using a trigger. my Assumption is Advisor__c is a look up on the ManagedFund__c object. I am also assuming the sum_total_investement__c field on the advisor object and total_investment on ManagedFund__c object.
Hope this helps!!
Regards
Sam
You can check my post at
http://boards.developerforce.com/t5/Apex-Code-Development/Rollup-summary-on-Contact/td-p/408625
It is a more comprehensive trigger which handles multiple scenarios.
Thanks guys for your help
Here is the final code (for those who need this) based Jose's code which is modified to fit my Org requirement
Thanks guys
I guess you will have a problem with inserts because of the usage of trigger.oldmap during insert
If so use the code below
Done!
Thanks,