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
m pandeym 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 Rvishnu 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){
accids.add(c.AccountID);
}
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;
accnames.add(a);
}
update accnames;
}


Please let us know if this will help you

thanks
 vishnu R

All Answers

vishnu Rvishnu 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){
accids.add(c.AccountID);
}
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;
accnames.add(a);
}
update accnames;
}


Please let us know if this will help you

thanks
 vishnu R
This was selected as the best answer
m pandeym pandey
This was so much help full to me..............
thank u so much buddy..............u Always rocks.............
may i know u r mail id........?
                    or                          
timings available in communities..............
m pandeym pandey
thank u so  much vishnu.........