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
SFDCAdmin73SFDCAdmin73 

Method does not exist or incorrect signature?

I am not strong in writing Apex Classes and Trigger and need assitance.

I am receiving the following error: Method does not exist or incorrect signature: populateRollUpFieldsOnOpportunity(newRecordsMap);

Here is the section of code for your reference. The error is on line 25. 
public with sharing class MultipleShipmentTrackingTriggerHandler {    
    public static set<Id> opptyIds = new set<Id>(); 
    public static boolean oliUpdateRunning = false;
    public static boolean doNotUpdateQuantity = false;
    public static boolean doNotUpdateAmount = false;
    
    public static void beforeInsertHandler(List<Multiple_Shipment_Tracking__c> newRecords){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecords);
        
        // populate fields on multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecords, false, null);     
    }
    
    public static void beforeUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecordsMap.values());            
        
        // populate fields on  multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecordsMap.values(), false, oldRecordsMap);
    }
    
    public static void afterInsertHandler(Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity(newRecordsMap);
    }
    
    public static void afterUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity(newRecordsMap);

 
Best Answer chosen by SFDCAdmin73
Mahesh DMahesh D
Hi

Line number 209 you have

public static void populateRollUpFieldsOnOpportunity(Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c> newRecords){

and at Line number 25, 30, 38 you have

populateRollUpFieldsOnOpportunity(newRecordsMap);

Here newRecordsMap is a Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap


Method is expecting Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c> and we are passing Map<Id,Multiple_Shipment_Tracking__c>


One morething here is anyway at line number 209, you are not using the parameter whichever you are sending hence we can remove that parameter:

Below is the modified code:

 
public with sharing class MultipleShipmentTrackingTriggerHandler {    
    public static set<Id> opptyIds = new set<Id>(); 
    public static boolean oliUpdateRunning = false;
    public static boolean doNotUpdateQuantity = false;
    public static boolean doNotUpdateAmount = false;
    
    public static void beforeInsertHandler(List<Multiple_Shipment_Tracking__c> newRecords){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecords);
        
        // populate fields on multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecords, false, null);     
    }
    
    public static void beforeUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecordsMap.values());            
        
        // populate fields on  multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecordsMap.values(), false, oldRecordsMap);
    }
    
    public static void afterInsertHandler(Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity();
    }
    
    public static void afterUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity();
    }
    
    public static void afterDeleteHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){
        // populate roll up calculation fields on opportunity
        for(On_Going_Revenue_by_Fiscal_Quarter__c revenue :oldRecordsMap.values()){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        populateRollUpFieldsOnOpportunity();
        //prePopulateFields(oldRecordsMap.values(), true, oldRecordsMap);
    }
    
    
    //Description:
    //Below method would be called in before insert and before update events.
    //It would validate the Product__c entered on Multiple_Shipment_Tracking__c object record, 
    //  the product must be from one of the related opportunity's line items.
    
    public static void validateProduct(List<Multiple_Shipment_Tracking__c> newRecords){
        Map<Id,set<Id>> OpptyIdToProductIdMap = new Map<Id,set<Id>>();
        List<OpportunityLineItem> olItems = new List<OpportunityLineItem>();    
            
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Quantity, TotalPrice from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!OpptyIdToProductIdMap.containsKey(oli.OpportunityId))
                OpptyIdToProductIdMap.put(oli.OpportunityId, new set<Id>{oli.Product2Id});
            else
                OpptyIdToProductIdMap.get(oli.OpportunityId).add(oli.Product2Id);
        }
        
        for(Multiple_Shipment_Tracking__c rev :newRecords){
            if(OpptyIdToProductIdMap.get(rev.PMI_Opportunity__c).contains(rev.Product__c))
                continue;
            else
                rev.addError('Product must be from related opportunity\'s product list.');
        }
                
    }
    
    //Description:
    //This method would be called from before insert and before update events.
    //It would populate some of the fields on Multiple_Shipment_Tracking__c record based
    //on the product(product__c) selected.
    
    public static void prePopulateFields(List<Multiple_Shipment_Tracking__c> newRecords, boolean isDelete, Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){        
        Map<Id, List<OpportunityLineItem>> productToLineItemMap = new Map<Id, List<OpportunityLineItem>>();         
        Map<Id, List<Multiple_Shipment_Tracking__c>> productToRevenueMap = new Map<Id, List<Multiple_Shipment_Tracking__c>>();
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Approved_Unit_Price__c, Quantity, TotalPrice, Approved_Extended_Price__c from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!productToLineItemMap.containsKey(oli.Product2Id))
                productToLineItemMap.put(oli.Product2Id, new List<OpportunityLineItem>{oli});
            else
                productToLineItemMap.get(oli.Product2Id).add(oli);
        }
        
        for(Multiple_Shipment_Tracking__c rev :[select Product__c, Remaining_Quantity__c, Remaining_Amount_to_Obtain__c, Total_Amount_Shipped__c, Quantity_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in :opptyIds order by lastmodifieddate desc]){
            if(!productToRevenueMap.containsKey(rev.Product__c))
                productToRevenueMap.put(rev.Product__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                productToRevenueMap.get(rev.Product__c).add(rev);
        }
        
        
        List<Multiple_Shipment_Tracking__c> revsToUpdate = new List<Multiple_Shipment_Tracking__c>();
        boolean includeRevFlag = false;
        decimal lastquantity = 0.00;
        
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            if(productToLineItemMap.containsKey(revenue.Product__c)){
                OpportunityLineItem relatedOli = productToLineItemMap.get(revenue.Product__c)[0];
                 if(!isDelete)
                    revenue.Unit_Price__c = relatedOli.Approved_Unit_Price__c;
                    
                    if(!productToRevenueMap.containsKey(revenue.Product__c)){  // there are no existing revenue for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(revenue.Quantity_Shipped__c <= relatedOli.Quantity){
                                revenue.Remaining_Quantity__c = string.valueOf(relatedOli.Quantity - revenue.Quantity_Shipped__c);
                            }else{
                                revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                            }
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            revenue.Remaining_Amount_to_Obtain__c = relatedOli.Approved_Extended_Price__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                        }
                        
                        ///********END*********** Amount Calculation ************************///
                        
                    }else{      // there are existing revenues for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                if(lastquantity == 0.00){
                                    decimal diffQ = relatedOli.Quantity - (revenue.Quantity_Shipped__c + Decimal.valueOf(revenue.Remaining_Quantity__c)) ;                               
                                    revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(revenue.Remaining_Quantity__c) + diffQ);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }else{
                                    revenue.Remaining_Quantity__c = string.valueOf(lastquantity - revenue.Quantity_Shipped__c);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }
                                
                            }else{
                                if(revenue.Quantity_Shipped__c <= Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c)){
                                    if(oldRecordsMap != null && revenue.Quantity_Shipped__c != oldRecordsMap.get(revenue.id).Quantity_Shipped__c){
                                        decimal oldQuantity = oldRecordsMap.get(revenue.id).Quantity_Shipped__c;                                    
                                        decimal diff = revenue.Quantity_Shipped__c > oldQuantity ? revenue.Quantity_Shipped__c - oldQuantity : oldQuantity - revenue.Quantity_Shipped__c ;
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - diff); 
                                    }else{
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - revenue.Quantity_Shipped__c );
                                    }
                                }else{
                                    revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                                }
                            }
                            
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) + revenue.Quantity_Shipped__c); 
                            // update these revenues
                            includeRevFlag = true;
                             //revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            
                            if(oldRecordsMap == null){      //insert operation
                                revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            }else{          // update operation
                                if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                    revenue.Remaining_Amount_to_Obtain__c = revenue.Remaining_Amount_to_Obtain__c - ((oldRecordsMap.get(revenue.id).Unit_Price__c - revenue.Unit_Price__c) * Decimal.valueOf(revenue.Remaining_Quantity__c));
                                    if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }
                                }else{
                                  if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }else{
                                      decimal lastAmountShipped = productToRevenueMap.get(revenue.Product__c)[0].Total_Amount_Shipped__c;                         
                                      revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                                      revenue.Remaining_Amount_to_Obtain__c = revenue.Total_Amount_Shipped__c > lastAmountShipped ? revenue.Remaining_Amount_to_Obtain__c + (revenue.Total_Amount_Shipped__c - lastAmountShipped) : revenue.Remaining_Amount_to_Obtain__c - (lastAmountShipped - revenue.Total_Amount_Shipped__c);
                                  }
                                }                               
                            }                                                   
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c + (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c > relatedOli.Approved_Extended_Price__c ? relatedOli.Approved_Extended_Price__c : productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c;
                            includeRevFlag = true;
                        }
                        ///********END*********** Amount Calculation ************************///
                        
                        if(includeRevFlag){
                            revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                            includeRevFlag = false;
                        }
                    }                                               
            }else{
                if(!isDelete)
                    revenue.addError('Product must be from related opportunity\'s product list.');  
            }       
        }
        
        // update revsToUpdate list here.
    }
    
    
    //Description:
    //This method would be called by after insert , after update and after delet events
    //it will populate fields on opportunity record. These fields on opportunity are being
    //used to store rolled up calculation for quarter specific revenue.
    
    public static void populateRollUpFieldsOnOpportunity(){
        Map<Id,Opportunity> opptymap = new Map<Id, Opportunity>([select Total_Amount_Q1__c, Total_Amount_Q2__c, Total_Amount_Q3__c, Total_Amount_Q4__c, Total_Amount_for_Current_FQ__c from Opportunity where Id in :opptyIds]);
        Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>> opptyToRevenueMap = new Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>>();
        
        system.debug('****** above query *** ');
        for(On_Going_Revenue_by_Fiscal_Quarter__c rev :[select Fiscal_Quarter__c, Fiscal_Year__c, Total_Amount_Shipped__c, PMI_Opportunity__c, createdDate, Fiscal_Quarter_Units_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in:opptyIds]){
            if(!opptyToRevenueMap.containsKey(rev.PMI_Opportunity__c))
                opptyToRevenueMap.put(rev.PMI_Opportunity__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                opptyToRevenueMap.get(rev.PMI_Opportunity__c).add(rev);
        }
        
        //////---START---- current fiscal quarter's start date, end date calculation///////////////////
        Period curr_fiscal_month = [Select StartDate, EndDate from Period where enddate >= today and startdate <= today and type='Quarter'];       
    
        Integer year = curr_fiscal_month.StartDate.year();
        Integer month = curr_fiscal_month.StartDate.month();
        Integer day = curr_fiscal_month.StartDate.day();
        Date strtDate_currentQuarter = date.newinstance(year, month, day);
        
        year = curr_fiscal_month.EndDate.year();
        month = curr_fiscal_month.EndDate.month();
        day = curr_fiscal_month.EndDate.day();
        Date endDate_currentQuarter = date.newinstance(year, month, day);
        //////---END---- current fiscal quarter's start date, end date calculation///////////////////
        string currentFiscalQuarter = '';
        if(month == 1 || month == 2 || month == 3){
          currentFiscalQuarter = 'Q4FY' + String.valueOf(Math.mod(year, 100));
        }else if(month == 4 || month == 5 || month == 6){
          currentFiscalQuarter = 'Q1FY' + String.valueOf(Math.mod(year, 100)+1);
        }else if(month == 7 || month == 8 || month == 9){
          currentFiscalQuarter = 'Q2FY' + String.valueOf(Math.mod(year, 100)+1);
        }else{
          currentFiscalQuarter = 'Q3FY' + String.valueOf(Math.mod(year, 100)+1);
        }
        
        
        if(!opptyToRevenueMap.isEmpty()){
            for(Id opp :opptyToRevenueMap.keySet()){
                decimal q1_amount=0.00,q2_amount=0.00,q3_amount=0.00,q4_amount=0.00;
                decimal total_amount_current_quarter = 0.00;
                
                for(Multiple_Shipment_Tracking__c revenu :opptyToRevenueMap.get(opp)){
                    string revenueCurrentQuarter = revenu.Fiscal_Quarter__c + revenu.Fiscal_Year__c;
                    // populate - total_amount_current_quarter
                        //if(revenu.createdDate >= strtDate_currentQuarter && revenu.createdDate <= endDate_currentQuarter)
                           // total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                        if(revenueCurrentQuarter.equalsIgnoreCase(currentFiscalQuarter))
                          total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                    
                    if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q1'))
                        q1_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q2'))
                        q2_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q3'))
                        q3_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q4'))
                        q4_amount += revenu.Total_Amount_Shipped__c;
                    else 
                        continue;
                }
                
                opptymap.get(opp).Total_Amount_Q1__c = q1_amount;
                opptymap.get(opp).Total_Amount_Q2__c = q2_amount;
                opptymap.get(opp).Total_Amount_Q3__c = q3_amount;
                opptymap.get(opp).Total_Amount_Q4__c = q4_amount;   
                opptymap.get(opp).Total_Amount_for_Current_FQ__c = total_amount_current_quarter;    
            }
        }else{
                for(Id oppId: opptymap.keySet()){
                    opptymap.get(oppId).Total_Amount_Q1__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q2__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q3__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q4__c = 0.00;  
                    opptymap.get(oppId).Total_Amount_for_Current_FQ__c = 0.00;
                }
        }
        
        
        if(opptymap.size()>0)
            update opptymap.values();
    }
}

Please do let me know if it helps you.

Regards,
Mahesh

All Answers

Mahesh DMahesh D
Hi

Please paste the full class so that it will be easy to answer your issue.

As this moment:

 
public static void populateRollUpFieldsOnOpportunity(Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap) {
}

Method doesn't exists in you.

Regards,
Mahesh
SFDCAdmin73SFDCAdmin73
public with sharing class MultipleShipmentTrackingTriggerHandler {    
    public static set<Id> opptyIds = new set<Id>(); 
    public static boolean oliUpdateRunning = false;
    public static boolean doNotUpdateQuantity = false;
    public static boolean doNotUpdateAmount = false;
    
    public static void beforeInsertHandler(List<Multiple_Shipment_Tracking__c> newRecords){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecords);
        
        // populate fields on multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecords, false, null);     
    }
    
    public static void beforeUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecordsMap.values());            
        
        // populate fields on  multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecordsMap.values(), false, oldRecordsMap);
    }
    
    public static void afterInsertHandler(Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity(newRecordsMap);
    }
    
    public static void afterUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity(newRecordsMap);
    }
    
    public static void afterDeleteHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){
        // populate roll up calculation fields on opportunity
        for(On_Going_Revenue_by_Fiscal_Quarter__c revenue :oldRecordsMap.values()){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        populateRollUpFieldsOnOpportunity(oldRecordsMap);
        //prePopulateFields(oldRecordsMap.values(), true, oldRecordsMap);
    }
    
    
    //Description:
    //Below method would be called in before insert and before update events.
    //It would validate the Product__c entered on Multiple_Shipment_Tracking__c object record, 
    //  the product must be from one of the related opportunity's line items.
    
    public static void validateProduct(List<Multiple_Shipment_Tracking__c> newRecords){
        Map<Id,set<Id>> OpptyIdToProductIdMap = new Map<Id,set<Id>>();
        List<OpportunityLineItem> olItems = new List<OpportunityLineItem>();    
            
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Quantity, TotalPrice from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!OpptyIdToProductIdMap.containsKey(oli.OpportunityId))
                OpptyIdToProductIdMap.put(oli.OpportunityId, new set<Id>{oli.Product2Id});
            else
                OpptyIdToProductIdMap.get(oli.OpportunityId).add(oli.Product2Id);
        }
        
        for(Multiple_Shipment_Tracking__c rev :newRecords){
            if(OpptyIdToProductIdMap.get(rev.PMI_Opportunity__c).contains(rev.Product__c))
                continue;
            else
                rev.addError('Product must be from related opportunity\'s product list.');
        }
                
    }
    
    //Description:
    //This method would be called from before insert and before update events.
    //It would populate some of the fields on Multiple_Shipment_Tracking__c record based
    //on the product(product__c) selected.
    
    public static void prePopulateFields(List<Multiple_Shipment_Tracking__c> newRecords, boolean isDelete, Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){        
        Map<Id, List<OpportunityLineItem>> productToLineItemMap = new Map<Id, List<OpportunityLineItem>>();         
        Map<Id, List<Multiple_Shipment_Tracking__c>> productToRevenueMap = new Map<Id, List<Multiple_Shipment_Tracking__c>>();
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Approved_Unit_Price__c, Quantity, TotalPrice, Approved_Extended_Price__c from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!productToLineItemMap.containsKey(oli.Product2Id))
                productToLineItemMap.put(oli.Product2Id, new List<OpportunityLineItem>{oli});
            else
                productToLineItemMap.get(oli.Product2Id).add(oli);
        }
        
        for(Multiple_Shipment_Tracking__c rev :[select Product__c, Remaining_Quantity__c, Remaining_Amount_to_Obtain__c, Total_Amount_Shipped__c, Quantity_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in :opptyIds order by lastmodifieddate desc]){
            if(!productToRevenueMap.containsKey(rev.Product__c))
                productToRevenueMap.put(rev.Product__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                productToRevenueMap.get(rev.Product__c).add(rev);
        }
        
        
        List<Multiple_Shipment_Tracking__c> revsToUpdate = new List<Multiple_Shipment_Tracking__c>();
        boolean includeRevFlag = false;
        decimal lastquantity = 0.00;
        
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            if(productToLineItemMap.containsKey(revenue.Product__c)){
                OpportunityLineItem relatedOli = productToLineItemMap.get(revenue.Product__c)[0];
                 if(!isDelete)
                    revenue.Unit_Price__c = relatedOli.Approved_Unit_Price__c;
                    
                    if(!productToRevenueMap.containsKey(revenue.Product__c)){  // there are no existing revenue for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(revenue.Quantity_Shipped__c <= relatedOli.Quantity){
                                revenue.Remaining_Quantity__c = string.valueOf(relatedOli.Quantity - revenue.Quantity_Shipped__c);
                            }else{
                                revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                            }
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            revenue.Remaining_Amount_to_Obtain__c = relatedOli.Approved_Extended_Price__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                        }
                        
                        ///********END*********** Amount Calculation ************************///
                        
                    }else{      // there are existing revenues for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                if(lastquantity == 0.00){
                                    decimal diffQ = relatedOli.Quantity - (revenue.Quantity_Shipped__c + Decimal.valueOf(revenue.Remaining_Quantity__c)) ;                               
                                    revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(revenue.Remaining_Quantity__c) + diffQ);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }else{
                                    revenue.Remaining_Quantity__c = string.valueOf(lastquantity - revenue.Quantity_Shipped__c);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }
                                
                            }else{
                                if(revenue.Quantity_Shipped__c <= Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c)){
                                    if(oldRecordsMap != null && revenue.Quantity_Shipped__c != oldRecordsMap.get(revenue.id).Quantity_Shipped__c){
                                        decimal oldQuantity = oldRecordsMap.get(revenue.id).Quantity_Shipped__c;                                    
                                        decimal diff = revenue.Quantity_Shipped__c > oldQuantity ? revenue.Quantity_Shipped__c - oldQuantity : oldQuantity - revenue.Quantity_Shipped__c ;
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - diff); 
                                    }else{
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - revenue.Quantity_Shipped__c );
                                    }
                                }else{
                                    revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                                }
                            }
                            
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) + revenue.Quantity_Shipped__c); 
                            // update these revenues
                            includeRevFlag = true;
                             //revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            
                            if(oldRecordsMap == null){      //insert operation
                                revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            }else{          // update operation
                                if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                    revenue.Remaining_Amount_to_Obtain__c = revenue.Remaining_Amount_to_Obtain__c - ((oldRecordsMap.get(revenue.id).Unit_Price__c - revenue.Unit_Price__c) * Decimal.valueOf(revenue.Remaining_Quantity__c));
                                    if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }
                                }else{
                                  if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }else{
                                      decimal lastAmountShipped = productToRevenueMap.get(revenue.Product__c)[0].Total_Amount_Shipped__c;                         
                                      revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                                      revenue.Remaining_Amount_to_Obtain__c = revenue.Total_Amount_Shipped__c > lastAmountShipped ? revenue.Remaining_Amount_to_Obtain__c + (revenue.Total_Amount_Shipped__c - lastAmountShipped) : revenue.Remaining_Amount_to_Obtain__c - (lastAmountShipped - revenue.Total_Amount_Shipped__c);
                                  }
                                }                               
                            }                                                   
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c + (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c > relatedOli.Approved_Extended_Price__c ? relatedOli.Approved_Extended_Price__c : productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c;
                            includeRevFlag = true;
                        }
                        ///********END*********** Amount Calculation ************************///
                        
                        if(includeRevFlag){
                            revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                            includeRevFlag = false;
                        }
                    }                                               
            }else{
                if(!isDelete)
                    revenue.addError('Product must be from related opportunity\'s product list.');  
            }       
        }
        
        // update revsToUpdate list here.
    }
    
    
    //Description:
    //This method would be called by after insert , after update and after delet events
    //it will populate fields on opportunity record. These fields on opportunity are being
    //used to store rolled up calculation for quarter specific revenue.
    
    public static void populateRollUpFieldsOnOpportunity(Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c> newRecords){
        Map<Id,Opportunity> opptymap = new Map<Id, Opportunity>([select Total_Amount_Q1__c, Total_Amount_Q2__c, Total_Amount_Q3__c, Total_Amount_Q4__c, Total_Amount_for_Current_FQ__c from Opportunity where Id in :opptyIds]);
        Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>> opptyToRevenueMap = new Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>>();
        
        system.debug('****** above query *** ');
        for(On_Going_Revenue_by_Fiscal_Quarter__c rev :[select Fiscal_Quarter__c, Fiscal_Year__c, Total_Amount_Shipped__c, PMI_Opportunity__c, createdDate, Fiscal_Quarter_Units_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in:opptyIds]){
            if(!opptyToRevenueMap.containsKey(rev.PMI_Opportunity__c))
                opptyToRevenueMap.put(rev.PMI_Opportunity__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                opptyToRevenueMap.get(rev.PMI_Opportunity__c).add(rev);
        }
        
        //////---START---- current fiscal quarter's start date, end date calculation///////////////////
        Period curr_fiscal_month = [Select StartDate, EndDate from Period where enddate >= today and startdate <= today and type='Quarter'];       
    
        Integer year = curr_fiscal_month.StartDate.year();
        Integer month = curr_fiscal_month.StartDate.month();
        Integer day = curr_fiscal_month.StartDate.day();
        Date strtDate_currentQuarter = date.newinstance(year, month, day);
        
        year = curr_fiscal_month.EndDate.year();
        month = curr_fiscal_month.EndDate.month();
        day = curr_fiscal_month.EndDate.day();
        Date endDate_currentQuarter = date.newinstance(year, month, day);
        //////---END---- current fiscal quarter's start date, end date calculation///////////////////
        string currentFiscalQuarter = '';
        if(month == 1 || month == 2 || month == 3){
          currentFiscalQuarter = 'Q4FY' + String.valueOf(Math.mod(year, 100));
        }else if(month == 4 || month == 5 || month == 6){
          currentFiscalQuarter = 'Q1FY' + String.valueOf(Math.mod(year, 100)+1);
        }else if(month == 7 || month == 8 || month == 9){
          currentFiscalQuarter = 'Q2FY' + String.valueOf(Math.mod(year, 100)+1);
        }else{
          currentFiscalQuarter = 'Q3FY' + String.valueOf(Math.mod(year, 100)+1);
        }
        
        
        if(!opptyToRevenueMap.isEmpty()){
            for(Id opp :opptyToRevenueMap.keySet()){
                decimal q1_amount=0.00,q2_amount=0.00,q3_amount=0.00,q4_amount=0.00;
                decimal total_amount_current_quarter = 0.00;
                
                for(Multiple_Shipment_Tracking__c revenu :opptyToRevenueMap.get(opp)){
                    string revenueCurrentQuarter = revenu.Fiscal_Quarter__c + revenu.Fiscal_Year__c;
                    // populate - total_amount_current_quarter
                        //if(revenu.createdDate >= strtDate_currentQuarter && revenu.createdDate <= endDate_currentQuarter)
                           // total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                        if(revenueCurrentQuarter.equalsIgnoreCase(currentFiscalQuarter))
                          total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                    
                    if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q1'))
                        q1_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q2'))
                        q2_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q3'))
                        q3_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q4'))
                        q4_amount += revenu.Total_Amount_Shipped__c;
                    else 
                        continue;
                }
                
                opptymap.get(opp).Total_Amount_Q1__c = q1_amount;
                opptymap.get(opp).Total_Amount_Q2__c = q2_amount;
                opptymap.get(opp).Total_Amount_Q3__c = q3_amount;
                opptymap.get(opp).Total_Amount_Q4__c = q4_amount;   
                opptymap.get(opp).Total_Amount_for_Current_FQ__c = total_amount_current_quarter;    
            }
        }else{
                for(Id oppId: opptymap.keySet()){
                    opptymap.get(oppId).Total_Amount_Q1__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q2__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q3__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q4__c = 0.00;  
                    opptymap.get(oppId).Total_Amount_for_Current_FQ__c = 0.00;
                }
        }
        
        
        if(opptymap.size()>0)
            update opptymap.values();
    }
}

 
Mahesh DMahesh D
Hi

Line number 209 you have

public static void populateRollUpFieldsOnOpportunity(Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c> newRecords){

and at Line number 25, 30, 38 you have

populateRollUpFieldsOnOpportunity(newRecordsMap);

Here newRecordsMap is a Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap


Method is expecting Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c> and we are passing Map<Id,Multiple_Shipment_Tracking__c>


One morething here is anyway at line number 209, you are not using the parameter whichever you are sending hence we can remove that parameter:

Below is the modified code:

 
public with sharing class MultipleShipmentTrackingTriggerHandler {    
    public static set<Id> opptyIds = new set<Id>(); 
    public static boolean oliUpdateRunning = false;
    public static boolean doNotUpdateQuantity = false;
    public static boolean doNotUpdateAmount = false;
    
    public static void beforeInsertHandler(List<Multiple_Shipment_Tracking__c> newRecords){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecords);
        
        // populate fields on multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecords, false, null);     
    }
    
    public static void beforeUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // validate the product , it must be from oppotunity line items
        validateProduct(newRecordsMap.values());            
        
        // populate fields on  multiple shipment tracking record based on the valid product selected
        prePopulateFields(newRecordsMap.values(), false, oldRecordsMap);
    }
    
    public static void afterInsertHandler(Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity();
    }
    
    public static void afterUpdateHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap, Map<Id,Multiple_Shipment_Tracking__c> newRecordsMap){
        // populate roll up calculation fields on opportunity
        populateRollUpFieldsOnOpportunity();
    }
    
    public static void afterDeleteHandler(Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){
        // populate roll up calculation fields on opportunity
        for(On_Going_Revenue_by_Fiscal_Quarter__c revenue :oldRecordsMap.values()){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        populateRollUpFieldsOnOpportunity();
        //prePopulateFields(oldRecordsMap.values(), true, oldRecordsMap);
    }
    
    
    //Description:
    //Below method would be called in before insert and before update events.
    //It would validate the Product__c entered on Multiple_Shipment_Tracking__c object record, 
    //  the product must be from one of the related opportunity's line items.
    
    public static void validateProduct(List<Multiple_Shipment_Tracking__c> newRecords){
        Map<Id,set<Id>> OpptyIdToProductIdMap = new Map<Id,set<Id>>();
        List<OpportunityLineItem> olItems = new List<OpportunityLineItem>();    
            
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            opptyIds.add(revenue.PMI_Opportunity__c);
        }
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Quantity, TotalPrice from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!OpptyIdToProductIdMap.containsKey(oli.OpportunityId))
                OpptyIdToProductIdMap.put(oli.OpportunityId, new set<Id>{oli.Product2Id});
            else
                OpptyIdToProductIdMap.get(oli.OpportunityId).add(oli.Product2Id);
        }
        
        for(Multiple_Shipment_Tracking__c rev :newRecords){
            if(OpptyIdToProductIdMap.get(rev.PMI_Opportunity__c).contains(rev.Product__c))
                continue;
            else
                rev.addError('Product must be from related opportunity\'s product list.');
        }
                
    }
    
    //Description:
    //This method would be called from before insert and before update events.
    //It would populate some of the fields on Multiple_Shipment_Tracking__c record based
    //on the product(product__c) selected.
    
    public static void prePopulateFields(List<Multiple_Shipment_Tracking__c> newRecords, boolean isDelete, Map<Id,Multiple_Shipment_Tracking__c> oldRecordsMap){        
        Map<Id, List<OpportunityLineItem>> productToLineItemMap = new Map<Id, List<OpportunityLineItem>>();         
        Map<Id, List<Multiple_Shipment_Tracking__c>> productToRevenueMap = new Map<Id, List<Multiple_Shipment_Tracking__c>>();
        
        for(OpportunityLineItem oli :[select Product2Id, OpportunityId, Approved_Unit_Price__c, Quantity, TotalPrice, Approved_Extended_Price__c from OpportunityLineItem where OpportunityId in :opptyIds]){
            if(!productToLineItemMap.containsKey(oli.Product2Id))
                productToLineItemMap.put(oli.Product2Id, new List<OpportunityLineItem>{oli});
            else
                productToLineItemMap.get(oli.Product2Id).add(oli);
        }
        
        for(Multiple_Shipment_Tracking__c rev :[select Product__c, Remaining_Quantity__c, Remaining_Amount_to_Obtain__c, Total_Amount_Shipped__c, Quantity_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in :opptyIds order by lastmodifieddate desc]){
            if(!productToRevenueMap.containsKey(rev.Product__c))
                productToRevenueMap.put(rev.Product__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                productToRevenueMap.get(rev.Product__c).add(rev);
        }
        
        
        List<Multiple_Shipment_Tracking__c> revsToUpdate = new List<Multiple_Shipment_Tracking__c>();
        boolean includeRevFlag = false;
        decimal lastquantity = 0.00;
        
        for(Multiple_Shipment_Tracking__c revenue :newRecords){
            if(productToLineItemMap.containsKey(revenue.Product__c)){
                OpportunityLineItem relatedOli = productToLineItemMap.get(revenue.Product__c)[0];
                 if(!isDelete)
                    revenue.Unit_Price__c = relatedOli.Approved_Unit_Price__c;
                    
                    if(!productToRevenueMap.containsKey(revenue.Product__c)){  // there are no existing revenue for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(revenue.Quantity_Shipped__c <= relatedOli.Quantity){
                                revenue.Remaining_Quantity__c = string.valueOf(relatedOli.Quantity - revenue.Quantity_Shipped__c);
                            }else{
                                revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                            }
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            revenue.Remaining_Amount_to_Obtain__c = relatedOli.Approved_Extended_Price__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                        }
                        
                        ///********END*********** Amount Calculation ************************///
                        
                    }else{      // there are existing revenues for this product
                        
                        ///********START*********** Quantity Calculation ************************///
                        if(!isDelete && !doNotUpdateQuantity){
                            if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                if(lastquantity == 0.00){
                                    decimal diffQ = relatedOli.Quantity - (revenue.Quantity_Shipped__c + Decimal.valueOf(revenue.Remaining_Quantity__c)) ;                               
                                    revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(revenue.Remaining_Quantity__c) + diffQ);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }else{
                                    revenue.Remaining_Quantity__c = string.valueOf(lastquantity - revenue.Quantity_Shipped__c);
                                    lastquantity = Decimal.valueOf(revenue.Remaining_Quantity__c) ;
                                }
                                
                            }else{
                                if(revenue.Quantity_Shipped__c <= Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c)){
                                    if(oldRecordsMap != null && revenue.Quantity_Shipped__c != oldRecordsMap.get(revenue.id).Quantity_Shipped__c){
                                        decimal oldQuantity = oldRecordsMap.get(revenue.id).Quantity_Shipped__c;                                    
                                        decimal diff = revenue.Quantity_Shipped__c > oldQuantity ? revenue.Quantity_Shipped__c - oldQuantity : oldQuantity - revenue.Quantity_Shipped__c ;
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - diff); 
                                    }else{
                                        revenue.Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) - revenue.Quantity_Shipped__c );
                                    }
                                }else{
                                    revenue.addError('Quantity entered is exceeding the remaining quantity for this product');
                                }
                            }
                            
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c = string.valueOf(Decimal.valueOf(productToRevenueMap.get(revenue.Product__c)[0].Remaining_Quantity__c) + revenue.Quantity_Shipped__c); 
                            // update these revenues
                            includeRevFlag = true;
                             //revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                        }
                        ///********END*********** Quantity Calculation ************************///
                        
                        ///********START*********** Amount Calculation ************************///
                        if(!isDelete && !doNotUpdateAmount){
                            
                            if(oldRecordsMap == null){      //insert operation
                                revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            }else{          // update operation
                                if(OnGoingRevenueTriggerHandler.oliUpdateRunning){
                                    revenue.Remaining_Amount_to_Obtain__c = revenue.Remaining_Amount_to_Obtain__c - ((oldRecordsMap.get(revenue.id).Unit_Price__c - revenue.Unit_Price__c) * Decimal.valueOf(revenue.Remaining_Quantity__c));
                                    if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }
                                }else{
                                  if(oldRecordsMap.get(revenue.id).Remaining_Quantity__c != revenue.Remaining_Quantity__c){
                                        revenue.Remaining_Amount_to_Obtain__c = Decimal.valueOf(revenue.Remaining_Quantity__c) * revenue.Unit_Price__c;
                                    }else{
                                      decimal lastAmountShipped = productToRevenueMap.get(revenue.Product__c)[0].Total_Amount_Shipped__c;                         
                                      revenue.Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c - (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                                      revenue.Remaining_Amount_to_Obtain__c = revenue.Total_Amount_Shipped__c > lastAmountShipped ? revenue.Remaining_Amount_to_Obtain__c + (revenue.Total_Amount_Shipped__c - lastAmountShipped) : revenue.Remaining_Amount_to_Obtain__c - (lastAmountShipped - revenue.Total_Amount_Shipped__c);
                                  }
                                }                               
                            }                                                   
                        }else{
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c + (revenue.Unit_Price__c * revenue.Quantity_Shipped__c);
                            productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c = productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c > relatedOli.Approved_Extended_Price__c ? relatedOli.Approved_Extended_Price__c : productToRevenueMap.get(revenue.Product__c)[0].Remaining_Amount_to_Obtain__c;
                            includeRevFlag = true;
                        }
                        ///********END*********** Amount Calculation ************************///
                        
                        if(includeRevFlag){
                            revsToUpdate.add(productToRevenueMap.get(revenue.Product__c)[0]);
                            includeRevFlag = false;
                        }
                    }                                               
            }else{
                if(!isDelete)
                    revenue.addError('Product must be from related opportunity\'s product list.');  
            }       
        }
        
        // update revsToUpdate list here.
    }
    
    
    //Description:
    //This method would be called by after insert , after update and after delet events
    //it will populate fields on opportunity record. These fields on opportunity are being
    //used to store rolled up calculation for quarter specific revenue.
    
    public static void populateRollUpFieldsOnOpportunity(){
        Map<Id,Opportunity> opptymap = new Map<Id, Opportunity>([select Total_Amount_Q1__c, Total_Amount_Q2__c, Total_Amount_Q3__c, Total_Amount_Q4__c, Total_Amount_for_Current_FQ__c from Opportunity where Id in :opptyIds]);
        Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>> opptyToRevenueMap = new Map<Id, List<On_Going_Revenue_by_Fiscal_Quarter__c>>();
        
        system.debug('****** above query *** ');
        for(On_Going_Revenue_by_Fiscal_Quarter__c rev :[select Fiscal_Quarter__c, Fiscal_Year__c, Total_Amount_Shipped__c, PMI_Opportunity__c, createdDate, Fiscal_Quarter_Units_Shipped__c from Multiple_Shipment_Tracking__c where PMI_Opportunity__c in:opptyIds]){
            if(!opptyToRevenueMap.containsKey(rev.PMI_Opportunity__c))
                opptyToRevenueMap.put(rev.PMI_Opportunity__c, new List<Multiple_Shipment_Tracking__c>{rev});
            else
                opptyToRevenueMap.get(rev.PMI_Opportunity__c).add(rev);
        }
        
        //////---START---- current fiscal quarter's start date, end date calculation///////////////////
        Period curr_fiscal_month = [Select StartDate, EndDate from Period where enddate >= today and startdate <= today and type='Quarter'];       
    
        Integer year = curr_fiscal_month.StartDate.year();
        Integer month = curr_fiscal_month.StartDate.month();
        Integer day = curr_fiscal_month.StartDate.day();
        Date strtDate_currentQuarter = date.newinstance(year, month, day);
        
        year = curr_fiscal_month.EndDate.year();
        month = curr_fiscal_month.EndDate.month();
        day = curr_fiscal_month.EndDate.day();
        Date endDate_currentQuarter = date.newinstance(year, month, day);
        //////---END---- current fiscal quarter's start date, end date calculation///////////////////
        string currentFiscalQuarter = '';
        if(month == 1 || month == 2 || month == 3){
          currentFiscalQuarter = 'Q4FY' + String.valueOf(Math.mod(year, 100));
        }else if(month == 4 || month == 5 || month == 6){
          currentFiscalQuarter = 'Q1FY' + String.valueOf(Math.mod(year, 100)+1);
        }else if(month == 7 || month == 8 || month == 9){
          currentFiscalQuarter = 'Q2FY' + String.valueOf(Math.mod(year, 100)+1);
        }else{
          currentFiscalQuarter = 'Q3FY' + String.valueOf(Math.mod(year, 100)+1);
        }
        
        
        if(!opptyToRevenueMap.isEmpty()){
            for(Id opp :opptyToRevenueMap.keySet()){
                decimal q1_amount=0.00,q2_amount=0.00,q3_amount=0.00,q4_amount=0.00;
                decimal total_amount_current_quarter = 0.00;
                
                for(Multiple_Shipment_Tracking__c revenu :opptyToRevenueMap.get(opp)){
                    string revenueCurrentQuarter = revenu.Fiscal_Quarter__c + revenu.Fiscal_Year__c;
                    // populate - total_amount_current_quarter
                        //if(revenu.createdDate >= strtDate_currentQuarter && revenu.createdDate <= endDate_currentQuarter)
                           // total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                        if(revenueCurrentQuarter.equalsIgnoreCase(currentFiscalQuarter))
                          total_amount_current_quarter += revenu.Total_Amount_Shipped__c;
                    
                    if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q1'))
                        q1_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q2'))
                        q2_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q3'))
                        q3_amount += revenu.Total_Amount_Shipped__c;
                    else if(revenu.Fiscal_Quarter__c != null && revenu.Fiscal_Quarter__c.equalsIgnoreCase('Q4'))
                        q4_amount += revenu.Total_Amount_Shipped__c;
                    else 
                        continue;
                }
                
                opptymap.get(opp).Total_Amount_Q1__c = q1_amount;
                opptymap.get(opp).Total_Amount_Q2__c = q2_amount;
                opptymap.get(opp).Total_Amount_Q3__c = q3_amount;
                opptymap.get(opp).Total_Amount_Q4__c = q4_amount;   
                opptymap.get(opp).Total_Amount_for_Current_FQ__c = total_amount_current_quarter;    
            }
        }else{
                for(Id oppId: opptymap.keySet()){
                    opptymap.get(oppId).Total_Amount_Q1__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q2__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q3__c = 0.00;
                    opptymap.get(oppId).Total_Amount_Q4__c = 0.00;  
                    opptymap.get(oppId).Total_Amount_for_Current_FQ__c = 0.00;
                }
        }
        
        
        if(opptymap.size()>0)
            update opptymap.values();
    }
}

Please do let me know if it helps you.

Regards,
Mahesh
This was selected as the best answer
Ravi Dutt SharmaRavi Dutt Sharma
On line 25, you are passing a map named newRecordsMap which is Map<Id,Multiple_Shipment_Tracking__c> whereas the populateRollUpFieldsOnOpportunity method expects Map<Id,On_Going_Revenue_by_Fiscal_Quarter__c>. 
If a method is expecting a map of Id, SomeObject, you need to pass it the same map, otherwise the compiler will throw an error that the method does not exist.
SFDCAdmin73SFDCAdmin73
Thanks Mahesh. That worked!