Roll Up Summary
Roll Up Summary
if(newOpp!=null){
for(Opportunity c : newOpp){
if(c.AccountId!=null){
oppByIds.add(c.AccountId);
}
}
}
if(oldOpp!=null){
for(Opportunity c : oldOppp){
oppByIds.add(c.AccountId);
}
}
---------------------------------------------------------
------------------
if(oppByIds.size()>0){
//Using Aggregate functions in SOQL, to Count(), SUM() and MAX(), for roll up
and summarize data in a query.
for(AggregateResult aggr:[SELECT
Count(Id)ids,AccountId,SUM(Amount)amt,MAX(Paid_On__c)maxdate
acc.Total_Amount__c = (Decimal)aggr.get('amt');
acc.Total_Opportunity__c = (Integer)aggr.get('ids');
acc.Recent_Pay__c = (Date)aggr.get('maxdate');
acc.Id = (Id)aggr.get('AccountId');
accountMapToUpdate.put(acc.Id, acc);
}
}
try{
update accountMapToUpdate.values();
}catch(Exception e){
System.debug('Exception Message'+e.getMessage()+'Line No.
>>'+e.getLineNumber());
}
}