You need to sign in to do that
Don't have an account?
sonam guptha
update is not working on existing records for sumof values
Hi,
Here iam adding sum of revenue__c to account column acc.Finance__c.
for Example :--
if opportunity.member__c.Revenue__c is 10
& opportunity.member__c.Revenue__c is 20
total = 30
this value iam printing on acc.Finance__c column,but now the problem is its keep on adding the values when we are changing the value on same record.
for example :--
for the same above record the value is 30.
if i change the same opportunity.member__c.Revenue__c is 10 to 20
& opportunity.member__c.Revenue__c is 20
the value should be 40 but here it counting has 50.
its counting the old value even.
can any one help me to resolve it??
Here iam adding sum of revenue__c to account column acc.Finance__c.
for Example :--
if opportunity.member__c.Revenue__c is 10
& opportunity.member__c.Revenue__c is 20
total = 30
this value iam printing on acc.Finance__c column,but now the problem is its keep on adding the values when we are changing the value on same record.
for example :--
for the same above record the value is 30.
if i change the same opportunity.member__c.Revenue__c is 10 to 20
& opportunity.member__c.Revenue__c is 20
the value should be 40 but here it counting has 50.
its counting the old value even.
can any one help me to resolve it??
trigger updateAccount on member__c (After Insert,After update,After Delete,) { List<Account> UpdateList = new List<Account>(); Id recTypeFinance = [select Id,name from RecordType where name='Finance' and SObjectType='member__c' limit 1].Id; string ids; if(Trigger.isInsert || Trigger.isUpdate) { for(Asset__c asst : Trigger.new) { if(asst.Opportunity__c != null) ids= asst.id; } For(member__c ast:[select Id,Opportunity__c,Revenue__c,RecordTypeId from member__c where ID=:ids]){ if(ast.RecordTypeId == recTypeFinance){ for(opportunity opp : [Select Id,AccountId from Opportunity where Id =: ast.Opportunity__c]){ for(Account acc : [Select Id,Finance__c from Account where Id =: opp.AccountId]){ if(acc.Finance__c == null){ acc.Finance__c= ast.Revenue__c; }else{ acc.Finance__c += ast.Revenue__c; } UpdateList.add(acc); } } } } update UpdateList; }
See on line 25 - If I don't set coming Con.Gorss_Amount_Total__c = 0.00 then it will add the new total on top of old one. Hope you can relate this to your trigger.
Trigger Code: Hope this helps!
The same thing iam doing on my above my code,here my problem is when ever i update the same existing record with different value,its adding the previous values to total,i need to calculate with the latest value.
for example :--
i entered a member record with value 5
&
second member record with value 10
total value should be 15,this is working fine.
When you go and change the second member record once again, from 10 to 20
Total value should be 5(first member record value)+20(second member latest value) = 25
But here its calculating like 5+10(previous value)+20 (latest value) = 35
this is something we need to modify our code using trigger.old when updating it again?