You need to sign in to do that
Don't have an account?
How to write same code for update operation
Hi all,
I have a requirement , Add all opportunity Amount fields , display total amount in Account object.
i have code it's working for inserting a record in opportunity.
But update and delete operation does not work.
i know through Roll-up summary we can but i want it from trigger only please help me ...........
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);
System.Debug('++++++opp.accountid--------Null--->'+acctotal.get(opp.accountid));
}
else
{
decimal amt = 0;
amt = acctotal.get(opp.accountid)+opp.amount;
acctotal.put(opp.accountid,amt);
System.debug('++++++++++opp.accountid--------NotNull--Total Amount---->'+acctotal.get(opp.accountid));
}
}
}
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);
System.debug('++++++++++opp.accountid--------finally---->'+a.total_amount__c);
}
update alist;
}
}
plz help me thank you guys,
Hi Premanath,
You have added following check in your code,
if(Trigger.isinsert){
Due to which your Trigger is limited to work for only insert case, However you have to include all the necessary events in your trigger for which you need to perform action.
Hi ,
yes for that pupous only i have posted my problm.
I don't know how to work with this for update operation.
please make it.
Thank you,
Hi guys,
No need any help , I have done it in my org.
Thank you