+ Start a Discussion
himanshu huske 7himanshu huske 7 

Please provide Test class for this scenerio

Objects: Contact and Property_c  
Property__c has Agent__c(lookUp to Contact)
1)   Contact has Default_commission_split__c field and Property has Agent_Commission_Per__c field
Whenever Default_commission_split__c get updated, Agent_Commission_Per__c should also get updated.
2)  Contact has Year_To_date_Total_Sales__c field and Property has Sales_price__c field
Year_To_date_Total_Sales__c should b sum of all Property record Sales_price__c field(Same as rollUp Summary
trigger Pupulate_Agent_And_AgentCommission on Property__c (before update,after update) {

        Populate_Agent_Commision pA = new Populate_Agent_Commision();
        pA.Agent_Commission(trigger.new, trigger.new);
        Calculate_YearToSaleDate_From_SalesPrice cY = new Calculate_YearToSaleDate_From_SalesPrice();

public class Populate_Agent_Commision {
    public  void Agent_Commission(List<Property__c> prop1,List<Property__c> prop2) {
          list<contact> contactlist = new list<contact>();
   set<id> pset = new set<id>();
       for (Property__c p1 : prop1){
        map<id,contact> conmap = new map<id,contact>();
   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);
    for(property__c p2: prop2){
        if(p2.status__C =='Closed Pending Approval'|| p2.Status__c =='Closed Approved'){
          p2.Agent_Commission_Per__c = conmap.get(p2.Agent__c).Default_commission_split__c;

public class Calculate_YearToSaleDate_From_SalesPrice {
    public void YearToSaleDate_Updation(list<Property__c> propList){
        Set<id> AgentId = new Set<id>();
    for(Property__c p1 : propList){
   list<Property__c> pList =  [Select id, Agent__c, Property_Name__c, Sales_price__c From Property__c Where Agent__c IN: AgentId];
    map<Id,list<Property__c>> conMap = new map<Id,list<Property__c>>();
    for(Property__c pr_1 : pList){
       conMap.put(pr_1.Agent__c, new list<Property__c>()); 
   list<Contact> conList = [Select id, Name, Year_To_date_Total_Sales__c from Contact Where id IN: conMap.keySet()];
    decimal amount = 0;
    for(Contact c1 : conList){
        for(Property__c pr_2: conMap.get(c1.Id)){
         amount += pr_2.Sales_price__c;  
       c1.Year_To_date_Total_Sales__c = amount;
   update conList;