You need to sign in to do that
Don't have an account?

how to combine these triggers
trigger expenses on Expense_Payouts__c (after insert,after update) { list<string> departmentnames= new list<string>(); Decimal amount; for(Expense_Payouts__c ep:trigger.new) { departmentnames.add(ep.department__c); amount=ep.Amount__c; } list<Employee__c> employee = [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from Employee__c where Department_Cost_Center__c IN:departmentnames]; system.debug('employeeeee.......'+employee); decimal divAmount; if(employee.size()!=null) { divAmount=amount/employee.size(); } system.debug('test.......'+divAmount); system.debug('test222222.......'+amount); for(Employee__c e:employee ) { if(e.Department_Cost_Center__c !='Others' && divAmount!=null) { e.Expense__c=((e.expense__C==null)?0:e.expense__C)+divAmount; } } update employee; } //////////////////trigger 2/////////////////////////// trigger otherdepartment on Expense_Payouts__c (after insert, after update) { list<employee__c> employ= [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from Employee__c]; decimal amount; for(Expense_Payouts__c e:trigger.new) { if(e.department__c=='Others') { amount=e.Amount__c; } } Decimal diamount; if(employ.size()!=null && amount!=null) { diamount=amount/employ.size(); } for(employee__c e:employ) { if(diamount!=null){ e.Company_Expenses__c=((e.Company_Expenses__c==null)?0:e.Company_Expenses__c)+diamount; } } update employ; }I Wrote two triggers on a same object..Now i am trying to merge them but cant able to merge both functionality in one trigger..
Please help by ur thoughts...
Thanks..........
All Answers
Yeah i am trying this..but i unable include this logic in in single trigger..
I am new to apex..Dont know how to query for differet logic..
if u could gives some ideas..it woll be very helpful ..thanks