You need to sign in to do that
Don't have an account?
Unique Two
Sum of an opportunity amount field on a custom object help required.
Hello
Because I can't use a roll up summary field how would I get the Sum of Opportunities FIeld Amount on to a Custom Object?
Because I can't use a roll up summary field how would I get the Sum of Opportunities FIeld Amount on to a Custom Object?
Trigger updateSum on Opportunity <after insert, after update, after delete, after undelete>{
List<Opportunity > newRecords = Trigger.new;
List<Opportunity > oldRecords = Trigger.new
if(trigger.isInsert || trigger.isUndelete){
Set<Id> cObjectId = new Set<Id>();
for(Opportunity newRecord : newRecords){
if(newRecord.amount != null){
cObjectId.add(newRecord.cObject__c);
}
}
if(!cObjectId.isEmpty() ){
List<cObject__c> cObjects =[select id, sumAmount__c, (select Id, Amount from Opportunities WHERE Amount != null) from cObject__c Where ID IN : cObjectId];
List<cObject__c> coToupdate = new List<cObject__c>();
if(cObjects != null){
for(cObject__c co : cObjects){
for(opportunity o : cObjects.Opportunitnies){
co.sumAmount__c += o.Amount;
}
coToUpdate.add(co);
}
update coToUpdate;
}
}
}
}
The object ID is 01I0l0000004PNl
The object name is Commissions
Opportunity {Amount} field to map to Commission Object Field {Settled Loan Value}
jseal04