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
DolgoldyDolgoldy 

Help for test clas

Hi all,

plz help me to write test class for this code
public class DateMathHelper {
    public static Integer dateMathCounter = 0;
    public static Integer dateMathLogicCounter = 0;
    
    public void calculateDateMath(List<Epix_Date_Math__c> dateMathList) {
        Set<Id> logicIds = new Set<Id>();
        
        for(Epix_Date_Math__c math : dateMathList) {		
            logicIds.add(math.Epix_Date_Math_Logic__c);
        }
        
        System.debug('DateMathHelper#1. logicIds -> ' + logicIds);
        
        AggregateResult [] mathAggregate = [Select Epix_Date_Math_Logic__c, MIN(Calculated_Date__c) Earliest, MAX(Calculated_Date__c) Latest
                                            from Epix_Date_Math__c Where Epix_Date_Math_Logic__c IN :logicIds Group BY Epix_Date_Math_Logic__c];
        
        System.debug('DateMathHelper#2. mathAggregate -> ' + mathAggregate);
        
        Map<Id, Epix_Date_Math_Logic__c> logicMap = new Map<Id, Epix_Date_Math_Logic__c>([Select Id, Logic__c, Calculated_Date__c from Epix_Date_Math_Logic__c Where ID IN :logicIds]);
        
        List<Epix_Date_Math_Logic__c> logicToUpdate = new List<Epix_Date_Math_Logic__c>();
        
        System.debug('DateMathHelper#3. logicMap -> ' + logicMap);
        System.debug('DateMathHelper#2. mathAggregate -> ' + mathAggregate);
        Set<Id> tdblogicIDs = new Set<Id>();
        // Gettig TBD records to calculate min Earliest date---------
        for(Epix_Date_Math__c M : [Select Epix_Date_Math_Logic__c from Epix_Date_Math__c Where Epix_Date_Math_Logic__c IN :logicIds and Calculated_Date__c = null])
        {
            tdblogicIDs.add(M.Epix_Date_Math_Logic__c);
        }
        
        for (AggregateResult ar : mathAggregate) {
            String logicId = (String)ar.get('Epix_Date_Math_Logic__c');
            if(logicMap.containsKey(logicId)){
                Epix_Date_Math_Logic__c logic = logicMap.get(logicId);   
                
                if(logic.Logic__c == 'Earliest Of' || logic.Logic__c == 'Equals')
                {
                    if(tdblogicIDs.contains(logicId)){
                        logic.Calculated_Date__c = null;
                    }else {
                    	logic.Calculated_Date__c = (Date)ar.get('Earliest');
                    }
                }else if(logic.Logic__c == 'Latest Of')
                    logic.Calculated_Date__c = (Date)ar.get('Latest');
                
                logicToUpdate.add(logic);
            }        
        }
        
        System.debug('DateMathHelper#4. logicToUpdate After -> ' + logicToUpdate);
        
        update logicToUpdate; 
    }
    
    public void updateDateMathLogic(List<Epix_Date_Math_Logic__c> dateLogicList) {
        System.debug('updateDateMathLogic -> ');
        Map<Id, String> milestoneIdvField = new Map<Id, String>();
        Map<Id, String> pickupIdvField = new Map<Id, String>();
        Map<Id, String> oppIdvField = new Map<Id, String>();
        
        Map<Id, Date> milestoneIdvDate = new Map<Id, Date>();
        Map<Id, Date> pickupIdvDate = new Map<Id, Date>();
        Map<Id, Date> oppIdvDate = new Map<Id, Date>();
        
        Set<String> milestoneFields = new Set<String>();
        Set<String> pickupFields = new Set<String>();
        Set<String> oppFields = new Set<String>();
        
        List<Milestone__c> mileStoneList = new List<Milestone__c>();
        List<Pickup_Options__c> pickupList = new List<Pickup_Options__c>();
        List<Opportunity> oppList = new List<Opportunity>();
        
        for(Epix_Date_Math_Logic__c logic : dateLogicList) {
            if(logic.Destination_Milestone__c!=null) {
                milestoneIdvField.put(logic.Destination_Milestone__c, logic.Column_Api__c);
                milestoneIdvDate.put(logic.Destination_Milestone__c, logic.Calculated_Date__c);
                milestoneFields.add(logic.Column_Api__c);
            }
            
            if(logic.Destination_Pickup_Option__c!=null) {
                pickupIdvField.put(logic.Destination_Pickup_Option__c, logic.Column_Api__c);
                pickupIdvDate.put(logic.Destination_Pickup_Option__c, logic.Calculated_Date__c);
                pickupFields.add(logic.Column_Api__c);
            }
            
            if(logic.Destination_Opportunity__c!=null) {
                oppIdvField.put(logic.Destination_Opportunity__c, logic.Column_Api__c);
                oppIdvDate.put(logic.Destination_Opportunity__c, logic.Calculated_Date__c);
                oppFields.add(logic.Column_Api__c);
            }
        }
        
        System.debug('DateMathLogic   milestoneIdvField -> ' + milestoneIdvField);
        System.debug('DateMathLogic   pickupIdvField -> ' + pickupIdvField);
        System.debug('DateMathLogic   oppIdvField -> ' + oppIdvField);
        
        System.debug('DateMathLogic   milestoneIdvDate -> ' + milestoneIdvDate);
        System.debug('DateMathLogic   pickupIdvDate -> ' + pickupIdvDate);
        System.debug('DateMathLogic   oppIdvDate -> ' + oppIdvDate);
        
        if(milestoneIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(milestoneFields);
            String cols = string.join(fields,',');
            Set<Id> keys = milestoneIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Milestone__c Where Id IN : keys';
            System.debug('DateMathLogic#1.  MileStone query -> ' + query);
            mileStoneList = Database.query(query);
        }
        
        if(pickupIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(pickupFields);
            String cols = string.join(fields,',');
            Set<Id> keys = pickupIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Pickup_Options__c Where Id IN : keys';
            System.debug('DateMathLogic#2.  Pickup query -> ' + query);
            pickupList = Database.query(query);
        }
        
        if(oppIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(oppFields);
            String cols = string.join(fields,',');
            Set<Id> keys = oppIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Opportunity Where Id IN : keys';
            System.debug('DateMathLogic#3.  Opportunity query -> ' + query);
            oppList = Database.query(query);
        }
        
        for( Milestone__c m : mileStoneList){
            System.debug('#4. MileStone -> ' + m);
            System.debug('#5. Field -> ' + milestoneIdvField.get(m.Id));
            System.debug('#6. Calculated Date -> ' + milestoneIdvDate.get(m.Id));
            m.put(milestoneIdvField.get(m.Id), milestoneIdvDate.get(m.Id));
        }
        
        for( Pickup_Options__c p : pickupList){
            System.debug('#7. Pickup -> ' + p);
            System.debug('#8. Field -> ' + pickupIdvField.get(p.Id));
            System.debug('#9. Calculated Date -> ' + pickupIdvDate.get(p.Id));
            p.put(pickupIdvField.get(p.Id), pickupIdvDate.get(p.Id));
        }
        
        for( Opportunity o : oppList){
            System.debug('#10. Intellect Property -> ' + o);
            System.debug('#11. Field -> ' + oppIdvField.get(o.Id));
            System.debug('#12. Calculated Date -> ' + oppIdvDate.get(o.Id));
            o.put(oppIdvField.get(o.Id), oppIdvDate.get(o.Id));
        }
        
        update mileStoneList;
        update pickupList;
        update oppList;
        
        System.debug('<-- updateDateMathLogic');
    }
}

 
Best Answer chosen by Dolgoldy
AnkaiahAnkaiah (Salesforce Developers) 
Hi Dolly,

try with below code and add the mandatory data in the test class.
Public class DateMathHelperTest {
    @isTest 
    Public static void DateMathHelpermethod1(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c = 'Earliest Of';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    } 
	
	@isTest 
    Public static void DateMathHelpermethod2(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be null
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod3(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be Latest Of
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod4(){
	
	   List<Epix_Date_Math_Logic__c> listedml = new List<Epix_Date_Math_Logic__c>();
	   
	   //// Add if there is anyother required fields are in Milestone__c data
	   Milestone__c m = new Milestone__c();
	   m.Name = 'test';
	   insert m;
	   
	   //// Add if there is anyother required fields are in Pickup_Options__c
	   Pickup_Options__c po = new Pickup_Options__c();
	   po.name = 'test';
	   insert po;
	   
	   // Add if there is anyother required fields are in opp
	   Opportunity opp = new Opportunity();
	   opp.Name = 'test opp';
	   opp.stageName = 'Prospect';
	   opp.closedate = system.today()+4;
	   insert opp;
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be Latest Of
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 edml.Destination_Milestone__c = 'm.id;
		 edml.Column_Api__c = 'test';
		 edml.Destination_Pickup_Option__c = po.id;
		 edml.Destination_Opportunity__c = opp.id;
		 listedml.add(edml);
		 
		 insert listedml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.updateDateMathLogic(listedm);
        Test.stopTest();
    }
	
	
}

If this helps, Please mark it as best answer.

Thanks!!

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Dolly,

try with below code and add the mandatory data in the test class.
Public class DateMathHelperTest {
    @isTest 
    Public static void DateMathHelpermethod1(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c = 'Earliest Of';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    } 
	
	@isTest 
    Public static void DateMathHelpermethod2(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be null
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod3(){
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be Latest Of
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod4(){
	
	   List<Epix_Date_Math_Logic__c> listedml = new List<Epix_Date_Math_Logic__c>();
	   
	   //// Add if there is anyother required fields are in Milestone__c data
	   Milestone__c m = new Milestone__c();
	   m.Name = 'test';
	   insert m;
	   
	   //// Add if there is anyother required fields are in Pickup_Options__c
	   Pickup_Options__c po = new Pickup_Options__c();
	   po.name = 'test';
	   insert po;
	   
	   // Add if there is anyother required fields are in opp
	   Opportunity opp = new Opportunity();
	   opp.Name = 'test opp';
	   opp.stageName = 'Prospect';
	   opp.closedate = system.today()+4;
	   insert opp;
	
	  // Add if there is anyother required fields are in Epix_Date_Math_Logic__c creation and Logic__c should be Latest Of
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 edml.Destination_Milestone__c = 'm.id;
		 edml.Column_Api__c = 'test';
		 edml.Destination_Pickup_Option__c = po.id;
		 edml.Destination_Opportunity__c = opp.id;
		 listedml.add(edml);
		 
		 insert listedml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        // Add if there is anyother required fields are in Epix_Date_Math__c creation
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Name = 'Salesforce', 
		                                            Epix_Date_Math_Logic__c=edml.id, 
													);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.updateDateMathLogic(listedm);
        Test.stopTest();
    }
	
	
}

If this helps, Please mark it as best answer.

Thanks!!
This was selected as the best answer
DolgoldyDolgoldy
Thank u for Early reply
DolgoldyDolgoldy
Hi ankaiah,

code help me lot
I update some field there 
but getting error as line 7, column 21: Static method cannot be referenced from a non static context: void DateMathHelper.calculateDateMath(List<Epix_Date_Math__c>) plz help in below code
@istest
Public class DateMathHelperTest {
    @isTest 
    Public static void DateMathHelpermethod1(){
	
	  
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 //edml.name = 'test';
		 edml.Logic__c = 'Equals';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
         Epix_Date_Math__c edm = new Epix_Date_Math__c(  Epix_Date_Math_Logic__c=edml.id);
													
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    } 
	
	@isTest 
    Public static void DateMathHelpermethod2(){
	
	  
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		// edml.name = 'test';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        
         Epix_Date_Math__c edm = new Epix_Date_Math__c(  Epix_Date_Math_Logic__c=edml.id);
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod3(){
	
	  
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 //edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 insert edml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
       Epix_Date_Math__c edm = new Epix_Date_Math__c(Epix_Date_Math_Logic__c=edml.id); 
													
        listedm.add(edm);
		insert listedm; 						
        
        Test.startTest();
        	DateMathHelper.calculateDateMath(listedm);
        Test.stopTest();
    }
	
	@isTest 
    Public static void DateMathHelpermethod4(){
	
	   List<Epix_Date_Math_Logic__c> listedml = new List<Epix_Date_Math_Logic__c>();
	   
	   
	   Milestone__c m = new Milestone__c();
	   m.Name = 'test';
	   insert m;
	   
	
	   Pickup_Options__c po = new Pickup_Options__c();
	  // po.name = 'test';
	   insert po;
	   
	   
	   Opportunity opp = new Opportunity();
	   opp.Name = 'test opp';
	   opp.stageName = 'Prospect';
	   opp.closedate = system.today()+4;
	   insert opp;
	
	  
	     Epix_Date_Math_Logic__c edml  = new Epix_Date_Math_Logic__c();
		 //edml.name = 'test';
		 edml.Logic__c ='Latest Of';
		 edml.Calculated_Date__c = system.today();
		 edml.Destination_Milestone__c = 'm.id';
		 edml.Column_Api__c = 'test';
		 edml.Destination_Pickup_Option__c = po.id;
		 edml.Destination_Opportunity__c = opp.id;
		 listedml.add(edml);
		 
		 insert listedml;
		 
		 List<Epix_Date_Math__c> listedm = new List<Epix_Date_Math__c>();
        
        
        Epix_Date_Math__c edm = new Epix_Date_Math__c(Epix_Date_Math_Logic__c='edml.id');
        listedm.add(edm);
		insert listedm; 						
        
       /* Test.startTest();
        	DateMathHelper.updateDateMathLogic(listedm);
        Test.stopTest();*/
    }
	
}

 
DolgoldyDolgoldy
plz help its urgent
 
AnkaiahAnkaiah (Salesforce Developers) 
Are you calling this apex class from trigger?
DolgoldyDolgoldy
yes
DolgoldyDolgoldy
this is trigger trigger DateMathTrigger on Epix_Date_Math__c (After Insert, After Update, After Delete) { if(Trigger.isAfter) { if(Trigger.isInsert || Trigger.isUpdate) { if(DateMathHelper.dateMathCounter
AnkaiahAnkaiah (Salesforce Developers) 
Then you can modify your class methods with static.
 
public class DateMathHelper {
    public static Integer dateMathCounter = 0;
    public static Integer dateMathLogicCounter = 0;
    
    public static void calculateDateMath(List<Epix_Date_Math__c> dateMathList) {
        Set<Id> logicIds = new Set<Id>();
        
        for(Epix_Date_Math__c math : dateMathList) {		
            logicIds.add(math.Epix_Date_Math_Logic__c);
        }
        
        System.debug('DateMathHelper#1. logicIds -> ' + logicIds);
        
        AggregateResult [] mathAggregate = [Select Epix_Date_Math_Logic__c, MIN(Calculated_Date__c) Earliest, MAX(Calculated_Date__c) Latest
                                            from Epix_Date_Math__c Where Epix_Date_Math_Logic__c IN :logicIds Group BY Epix_Date_Math_Logic__c];
        
        System.debug('DateMathHelper#2. mathAggregate -> ' + mathAggregate);
        
        Map<Id, Epix_Date_Math_Logic__c> logicMap = new Map<Id, Epix_Date_Math_Logic__c>([Select Id, Logic__c, Calculated_Date__c from Epix_Date_Math_Logic__c Where ID IN :logicIds]);
        
        List<Epix_Date_Math_Logic__c> logicToUpdate = new List<Epix_Date_Math_Logic__c>();
        
        System.debug('DateMathHelper#3. logicMap -> ' + logicMap);
        System.debug('DateMathHelper#2. mathAggregate -> ' + mathAggregate);
        Set<Id> tdblogicIDs = new Set<Id>();
        // Gettig TBD records to calculate min Earliest date---------
        for(Epix_Date_Math__c M : [Select Epix_Date_Math_Logic__c from Epix_Date_Math__c Where Epix_Date_Math_Logic__c IN :logicIds and Calculated_Date__c = null])
        {
            tdblogicIDs.add(M.Epix_Date_Math_Logic__c);
        }
        
        for (AggregateResult ar : mathAggregate) {
            String logicId = (String)ar.get('Epix_Date_Math_Logic__c');
            if(logicMap.containsKey(logicId)){
                Epix_Date_Math_Logic__c logic = logicMap.get(logicId);   
                
                if(logic.Logic__c == 'Earliest Of' || logic.Logic__c == 'Equals')
                {
                    if(tdblogicIDs.contains(logicId)){
                        logic.Calculated_Date__c = null;
                    }else {
                    	logic.Calculated_Date__c = (Date)ar.get('Earliest');
                    }
                }else if(logic.Logic__c == 'Latest Of')
                    logic.Calculated_Date__c = (Date)ar.get('Latest');
                
                logicToUpdate.add(logic);
            }        
        }
        
        System.debug('DateMathHelper#4. logicToUpdate After -> ' + logicToUpdate);
        
        update logicToUpdate; 
    }
    
    public static void updateDateMathLogic(List<Epix_Date_Math_Logic__c> dateLogicList) {
        System.debug('updateDateMathLogic -> ');
        Map<Id, String> milestoneIdvField = new Map<Id, String>();
        Map<Id, String> pickupIdvField = new Map<Id, String>();
        Map<Id, String> oppIdvField = new Map<Id, String>();
        
        Map<Id, Date> milestoneIdvDate = new Map<Id, Date>();
        Map<Id, Date> pickupIdvDate = new Map<Id, Date>();
        Map<Id, Date> oppIdvDate = new Map<Id, Date>();
        
        Set<String> milestoneFields = new Set<String>();
        Set<String> pickupFields = new Set<String>();
        Set<String> oppFields = new Set<String>();
        
        List<Milestone__c> mileStoneList = new List<Milestone__c>();
        List<Pickup_Options__c> pickupList = new List<Pickup_Options__c>();
        List<Opportunity> oppList = new List<Opportunity>();
        
        for(Epix_Date_Math_Logic__c logic : dateLogicList) {
            if(logic.Destination_Milestone__c!=null) {
                milestoneIdvField.put(logic.Destination_Milestone__c, logic.Column_Api__c);
                milestoneIdvDate.put(logic.Destination_Milestone__c, logic.Calculated_Date__c);
                milestoneFields.add(logic.Column_Api__c);
            }
            
            if(logic.Destination_Pickup_Option__c!=null) {
                pickupIdvField.put(logic.Destination_Pickup_Option__c, logic.Column_Api__c);
                pickupIdvDate.put(logic.Destination_Pickup_Option__c, logic.Calculated_Date__c);
                pickupFields.add(logic.Column_Api__c);
            }
            
            if(logic.Destination_Opportunity__c!=null) {
                oppIdvField.put(logic.Destination_Opportunity__c, logic.Column_Api__c);
                oppIdvDate.put(logic.Destination_Opportunity__c, logic.Calculated_Date__c);
                oppFields.add(logic.Column_Api__c);
            }
        }
        
        System.debug('DateMathLogic   milestoneIdvField -> ' + milestoneIdvField);
        System.debug('DateMathLogic   pickupIdvField -> ' + pickupIdvField);
        System.debug('DateMathLogic   oppIdvField -> ' + oppIdvField);
        
        System.debug('DateMathLogic   milestoneIdvDate -> ' + milestoneIdvDate);
        System.debug('DateMathLogic   pickupIdvDate -> ' + pickupIdvDate);
        System.debug('DateMathLogic   oppIdvDate -> ' + oppIdvDate);
        
        if(milestoneIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(milestoneFields);
            String cols = string.join(fields,',');
            Set<Id> keys = milestoneIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Milestone__c Where Id IN : keys';
            System.debug('DateMathLogic#1.  MileStone query -> ' + query);
            mileStoneList = Database.query(query);
        }
        
        if(pickupIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(pickupFields);
            String cols = string.join(fields,',');
            Set<Id> keys = pickupIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Pickup_Options__c Where Id IN : keys';
            System.debug('DateMathLogic#2.  Pickup query -> ' + query);
            pickupList = Database.query(query);
        }
        
        if(oppIdvField.size() > 0){
            List<String> fields = new List<String>();
            fields.addAll(oppFields);
            String cols = string.join(fields,',');
            Set<Id> keys = oppIdvField.keyset();
            String query = 'Select Id, ' + cols + ' From Opportunity Where Id IN : keys';
            System.debug('DateMathLogic#3.  Opportunity query -> ' + query);
            oppList = Database.query(query);
        }
        
        for( Milestone__c m : mileStoneList){
            System.debug('#4. MileStone -> ' + m);
            System.debug('#5. Field -> ' + milestoneIdvField.get(m.Id));
            System.debug('#6. Calculated Date -> ' + milestoneIdvDate.get(m.Id));
            m.put(milestoneIdvField.get(m.Id), milestoneIdvDate.get(m.Id));
        }
        
        for( Pickup_Options__c p : pickupList){
            System.debug('#7. Pickup -> ' + p);
            System.debug('#8. Field -> ' + pickupIdvField.get(p.Id));
            System.debug('#9. Calculated Date -> ' + pickupIdvDate.get(p.Id));
            p.put(pickupIdvField.get(p.Id), pickupIdvDate.get(p.Id));
        }
        
        for( Opportunity o : oppList){
            System.debug('#10. Intellect Property -> ' + o);
            System.debug('#11. Field -> ' + oppIdvField.get(o.Id));
            System.debug('#12. Calculated Date -> ' + oppIdvDate.get(o.Id));
            o.put(oppIdvField.get(o.Id), oppIdvDate.get(o.Id));
        }
        
        update mileStoneList;
        update pickupList;
        update oppList;
        
        System.debug('<-- updateDateMathLogic');
    }
}

 
DolgoldyDolgoldy
already did that changes but still getting error
AnkaiahAnkaiah (Salesforce Developers) 
Just now i saw your trigger.

You need to modify like below.
this is trigger trigger DateMathTrigger on Epix_Date_Math__c (After Insert, After Update, After Delete) { 
if(Trigger.isAfter) 
{ 
if(Trigger.isInsert || Trigger.isUpdate) { if(DateMathHelper.dateMathCounter(trigger.new);
}