Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
m pandey

# salaries of contacts should be calculated and total of salary should be updated in account field of salary in trigger.?

account -  fld-Total sal-intger r currncy

contact -fld  -sal of cntct-intger r currncy

when ever we create cntct  and sal is added in the field all cntct sal of total should be updated in account total sal field

Task-ex: if we have 5 cntcts of sal(10.000,25.0000,55.444,22.000,77.0000) while creating f recrd and updatng the recrd in sal fld in cntcts
it should be total in accnt fild total salary.....?
Best Answer chosen by m pandey
vishnu R
hi pandey,

try this code....
Trigger::
trigger SumUpSalaryInAccount on Contact (after update,after insert) {
list<id> accids=new list<id>();
list<account> accnames=new list<account>();
for(Contact c:trigger.new){
}
List<Account> accs=new List<Account>([select id, shobithapp__contact_name__c,shobithapp__total_salary_del__c,(select id,Name,shobithapp__Salary__c from contacts) from Account where id in:accids]);
decimal n=0.00;
for(Account a:accs){
for(Contact c1:a.Contacts){
n=n+c1.shobithapp__Salary__c ;
}
a.shobithapp__total_salary_del__c=n;
}
update accnames;
}

thanks
vishnu R

vishnu R
hi pandey,

try this code....
Trigger::
trigger SumUpSalaryInAccount on Contact (after update,after insert) {
list<id> accids=new list<id>();
list<account> accnames=new list<account>();
for(Contact c:trigger.new){
}
List<Account> accs=new List<Account>([select id, shobithapp__contact_name__c,shobithapp__total_salary_del__c,(select id,Name,shobithapp__Salary__c from contacts) from Account where id in:accids]);
decimal n=0.00;
for(Account a:accs){
for(Contact c1:a.Contacts){
n=n+c1.shobithapp__Salary__c ;
}
a.shobithapp__total_salary_del__c=n;
}
update accnames;
}