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

please provide this code using handler class
trigger Trg_Property_Contact on Property__c (before update,after update) { String UserID = UserInfo.getUserId(); list<contact> contactlist = new list<contact>(); set<id> pset = new set<id>(); map<id,contact> conmap = new map<id,Contact>(); for (Property__c p : trigger.new){ pset.add(p.Agent__c); } list<contact> conlist = [select id,name,Default_commission_split__c,Year_To_date_Total_Sales__c from contact where id in: pset]; for(contact c : conlist){ conmap.put(c.id, c); } if(trigger.isbefore){ for(property__c p1: trigger.new){ if(p1.status__C =='Closed Pending Approval'|| p1.Status__c =='Closed Approved'){ p1.Agent_Commission_Per__c = conmap.get(p1.Agent__c).Default_commission_split__c; } } } if(trigger.isafter){ set<id> myset = new set<id>(); map<id,contact> cmap = new map<id,Contact>(); list<contact> contactlist = new list<contact>(); for (Property__c p : trigger.old){ myset.add(p.Agent__c); } list<contact> conlist = [select id,name,Default_commission_split__c,Year_To_date_Total_Sales__c from contact where id in: myset]; for(contact ct : conlist){ cmap.put(ct.id, ct); } for(property__c p3: trigger.old){ if(p3.status__C =='Closed Pending Approval'){ if(cmap.containskey(p3.Agent__c)){ contact c1 = cmap.get(p3.Agent__c); c1.Year_To_date_Total_Sales__c = c1.Year_To_date_Total_Sales__c + p3.Sales_price__c; } } } update contactlist; } }