function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC@ErrorSFDC@Error 

Sum of record value

Hi All
How can i sum the last record value with new one.For example i have created a record with field value 400.again i  create another record with filed value 500 ,then how i will add this field value like 400+500=900 in second record  and so on..
Salesforce seekarSalesforce seekar
hi , 

use this code accordingly, ie displaying several  Amount__c  values  of contacts and sending the total to Account

acclist =[select id,name,Total_Amount__c,(select id, name ,Amount__c from contacts) from Account where id in: AccID];
  }
  for(Account acc  :acclist )
  {
  integer sum =0; 

        for(contact cont : acc.contacts)
        {
        system.debug('contAmount====='+cont.Amount__c);
           sum += cont.Amount__c ;
        }
        acc.Total_Amount__c= val;
    }