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

Adding Child Values and showing in parent object
Hi Guys,
I want to execute some logic via developer console , because i need to sum up child values and i need to show it in Parent object.for this my logic is,
set<Id> actids = new set<Id>();
List<opportunity> lstopps=[select id,name,closedate,expectedrevenue,accountid from opportunity ];
for(opportunity o:lstopps){
if(o.closedate.year()==Integer.valueof('2014')){
actids.add(o.accountid);
}
}
Map<Id,Account> acctsmap = new Map<Id,Account>([select id,name,Total_Revenue__c from account where id IN:actids]);
for(Account a:acctsmap.values()){
a.Total_Revenue__c=0;
}
if(actids.size()>0){
for(opportunity o:[select id,name,closedate,expectedrevenue,accountid from opportunity where accountid =:actids]){
Account ac=acctsmap.get(o.accountid);
if(ac.Total_Revenue__c!=0){
ac.Total_Revenue__c+=o.ExpectedRevenue;
}else{
ac.Total_Revenue__c=o.ExpectedRevenue;
}
}
}
update acctsmap.values();
I want to execute some logic via developer console , because i need to sum up child values and i need to show it in Parent object.for this my logic is,
set<Id> actids = new set<Id>();
List<opportunity> lstopps=[select id,name,closedate,expectedrevenue,accountid from opportunity ];
for(opportunity o:lstopps){
if(o.closedate.year()==Integer.valueof('2014')){
actids.add(o.accountid);
}
}
Map<Id,Account> acctsmap = new Map<Id,Account>([select id,name,Total_Revenue__c from account where id IN:actids]);
for(Account a:acctsmap.values()){
a.Total_Revenue__c=0;
}
if(actids.size()>0){
for(opportunity o:[select id,name,closedate,expectedrevenue,accountid from opportunity where accountid =:actids]){
Account ac=acctsmap.get(o.accountid);
if(ac.Total_Revenue__c!=0){
ac.Total_Revenue__c+=o.ExpectedRevenue;
}else{
ac.Total_Revenue__c=o.ExpectedRevenue;
}
}
}
update acctsmap.values();
Looks like the flow is missing in the loop some where.
ENable debug logs and see till where the code is being parsed.
Also check if you are getting any warnings or errors.
Regards,
Ashish