You need to sign in to do that
Don't have an account?
bela
can any one help me in this trigger,I am writting a trigger,which is displaying amount of opportunity of account in account field
can any one help me in this trigger,I am writting a trigger,which is displaying amount of opportunities of account in account field.I tried in below way,but i am getting this error execution of AfterInsert caused by: System.NullPointerException: Argument cannot be null.: Trigger.addoppamount: line 18, column 1 and also getting another error at line 16 line ,can any one explain where i did mistake
trigger addoppamount on opportunity(after update,after insert) {
set<id> s=new set<id>();
for (opportunity op:trigger.new){
s.add(op.accountid);
}
map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);
for(opportunity opp:trigger.new){
Account acc = new Account();
acc.id=ma.get(opp.accountid).id;
list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities) from account where id =: acc.id];
system.debug('hiiiiiii'+af);
for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
{
acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error
system.debug('hiiiiiii'+acc.total_opportunity_amount__c);
}
update acc;
}
}
trigger addoppamount on opportunity(after update,after insert) {
set<id> s=new set<id>();
for (opportunity op:trigger.new){
s.add(op.accountid);
}
map<id,account> ma =new map<id,account>([select id,name,total_opportunity_amount__c ,(select id from opportunities) from account where id in :s]);
for(opportunity opp:trigger.new){
Account acc = new Account();
acc.id=ma.get(opp.accountid).id;
list<account> af= [select id,name,total_opportunity_amount__c,(select id from opportunities) from account where id =: acc.id];
system.debug('hiiiiiii'+af);
for(integer i =0;i<af.oppotunities.size();i++)//In for loop it is not accepting af.oppotunities.size() and giving Initial term of field expression must be a concrete SObject: List<Account> at line 16 column 28 but it is taking like this i<af.oppotunities.size(),can any one explain why
{
acc.total_opportunity_amount__c =opp.amount + acc.total_opportunity_amount__c;//18th line Here it is showing error
system.debug('hiiiiiii'+acc.total_opportunity_amount__c);
}
update acc;
}
}
what heppen when any opportunity is deleted or undeleted ?? in this case your total_opportunity_amount__c field not update on account record
use below trigger code for do it let me inform if it helps you
thanks
Thanks for the reply,actually i want to know what is the mistake i did in my trigger and why i am getting the error and how to solve it.so please help me to understand the mistake.