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
MohiniMohini 

I need help with the trigger for the below apex . Any help will really be graceful

Overall, this Apex class calculates and manages MCV Amount  (MCV Line Items object )records related to OpportunityLineItems, considering proration, rate increases, and other related attributes. It provides methods for creating, updating, and deleting MCV records based on changes in OpportunityLineItems. Both are md relation with opportunity.   I have added a method to calculate MCV Amount only for a specific product and to apply discount only to this product .. Now the existing trigger is not working with the updated method or the older method ,                                                                                            Apex :
/**
 * Kartik (NeuraFlash)
 * Service Class for OpportunityProducts related functionality
 */
public with sharing class OpportunityProductService {
	

	/**
	 * Calculate the MCVs for each of the Line item for next 18 months, consider prorates
	 * @param  lineItems [The line items for which we need to calculate the MCVs]
	 * @return           [description]
	 */
	
	@testVisible
	private static PriceBook2 standardPriceBook;

	public static String calculateMCVs(List<OpportunityLineItem> lineItems) {

		List<MCVStructure> mcvs = new List<MCVStructure>();
		Set<Id> opportunityIds  = new Set<Id>();
        Set<Id> RCSOpptIds = new Set<Id>();
		Map<Id,Opportunity> opportunityMap = new Map<Id,Opportunity>();
		Map<Id,Product2> pricebookEntryToProductMap = new Map<Id,Product2>();
		Map<Id,Product2> productMap = new Map<Id,Product2>();
        List<Opportunity> RCSOpptsToUpdate = new List<Opportunity>();
        

		if (!Test.isRunningTest())
			standardPriceBook = [Select Id, Name from PriceBook2 where isStandard = true LIMIT 1];

		for (PriceBookEntry pbe : [Select Id, Product2Id, Name, Product2.Upfront_Fee__c from PriceBookEntry where PriceBook2Id = :standardPriceBook.Id]) {
			pricebookEntryToProductMap.put(pbe.Id,new Product2(Id=pbe.Product2Id,Upfront_Fee__c=pbe.Product2.Upfront_Fee__c));
		}

		for (OpportunityLineItem oli : lineItems) {
			opportunityIds.add(oli.OpportunityId);
		}
        // MV -- Added Code for RCS
        for (AggregateResult aggRes : [SELECT COUNT(ID) numRCS, OpportunityId
              FROM OpportunityLineItem
            	where Product2Id IN (select Id from Product2 where isActive =true and family IN ('Recyclers', 'CompuSafe'))
                 and OpportunityId IN :opportunityIds
					and OpportunityId not in (select Id from Opportunity where Has_RCS_Product__c = true)
              GROUP BY OpportunityId limit 200]) {
            
            Id OpportunityId = (Id) aggRes.get('OpportunityId');
            Integer numRCS = (Integer) aggRes.get('numRCS');
                  
            if (numRCS > 0)
                RCSOpptIds.add(OpportunityId);
        }

		for (Opportunity opp : [Select Id, Name, Account.Name, Account.Rate_Increase__c, Account.Rate_Increase_terms__c, Term__c, Rate_Increase_Date__c, Has_RCS_Product__c from Opportunity where Id in :opportunityIds]) {
            //MV 07-24-2019 - If it's RCS Oppt, Set the flag to true
            if (RCSOpptIds.contains(opp.Id)) 
            {
                opp.Has_RCS_Product__c=true;
                RCSOpptsToUpdate.add(opp);
            }
			opportunityMap.put(opp.Id,opp);
		}
        
        update RCSOpptsToUpdate;

		for (OpportunityLineItem oli : lineItems) {
			
			if (oli.ServiceDate == null)
				oli.ServiceDate = oli.CreatedDate.date();

			// Prepare for MCV Calculation
			Double rateIncrease 		= opportunityMap.get(oli.OpportunityId).Account.Rate_Increase__c != null ? opportunityMap.get(oli.OpportunityId).Account.Rate_Increase__c : 0;
			String rateIncreaseTerms 	= opportunityMap.get(oli.OpportunityId).Rate_Increase_Date__c != null ? opportunityMap.get(oli.OpportunityId).Rate_Increase_Date__c : 'Anniversary';
			Integer term 				= opportunityMap.get(oli.OpportunityId).Term__c != null ? Integer.valueof(opportunityMap.get(oli.OpportunityId).Term__c) : 18; 

			// If the product has Upfront Fee checked on, skip calculating MCV for term 
			// and do it only for one Service Start Date.

			if (pricebookEntryToProductMap.get(oli.PricebookEntryId).Upfront_Fee__c) {
				
				Date startingMonth 			= oli.ServiceDate.toStartOfMonth();
				MCVStructure mcv 			= new MCVStructure(oli.Id,startingMonth,oli.TotalPrice,false);
				mcv.theOpportunityId 		= oli.OpportunityId;
				mcv.accountName 			= opportunityMap.get(oli.OpportunityId).Account.Name;
				mcv.productId   			= pricebookEntryToProductMap.get(oli.PricebookEntryId).Id;
				mcv.lineItem     			= oli;
                mcv.upfrontFeeProduct		= true;
				mcvs.add(mcv);
				// Skip into the next line item. 
				continue;
			}


			// Calculate the Pro-rated if the Service Start Date is in middle of the month.
			Date startingMonth 			= oli.ServiceDate.toStartOfMonth();
			Integer daysRemaining 		= oli.ServiceDate.daysBetween(oli.ServiceDate.addMonths(+1).toStartOfMonth());
			Integer daysInMonth 		= Date.daysInMonth(oli.ServiceDate.year(),oli.ServiceDate.month());
			Decimal proratedUnitPrice 	= 0;
			
			// If Trip rate, prorate based on number of days left over in a month
			if (oli.Monthly_or_Trip_Rate__c == 'Trip') {
				DaysWrapper dWrapper = getDaysInMonth(oli.ServiceDate.year(),oli.ServiceDate.month(),oli.ServiceDate.day());
				Integer numberOfTripsInMonth = getTotalTripsInMonth(oli,dWrapper);
				proratedUnitPrice = oli.TotalPrice * numberOfTripsInMonth;
			} else {
				proratedUnitPrice = (oli.TotalPrice/daysInMonth) * daysRemaining;
			}	

			MCVStructure mcv = new MCVStructure(oli.Id,startingMonth,proratedUnitPrice,false);
			mcv.theOpportunityId = oli.OpportunityId;
			mcv.accountName = opportunityMap.get(oli.OpportunityId).Account.Name;
			mcv.productId   = pricebookEntryToProductMap.get(oli.PricebookEntryId).Id;
			mcv.lineItem     = oli;
			mcvs.add(mcv);

			// Unit Price and Rate increase
			Decimal rateIncreaseUnitPrice = oli.TotalPrice + (oli.TotalPrice * rateIncrease/100);
			Decimal rateIncreaseUnitPriceBuffer = rateIncreaseUnitPrice;
			Boolean rateIncreaseApplied = false;
			Integer termYearFiller = 12 + (12 - oli.ServiceDate.month());

			// MCV for the term.
			for (Integer i=1;i<term;i++) {
				// Reset the Unit Price.
				Decimal unitPrice = oli.TotalPrice;
				// Reset the RateIncreaseUnitPrice
				if (!rateIncreaseApplied)
					rateIncreaseUnitPrice = oli.TotalPrice + (oli.TotalPrice * rateIncrease/100);
				else
					rateIncreaseUnitPrice = rateIncreaseUnitPriceBuffer;

				// The rate increase is based on 2 options
				// Anniversary - Anniversary is straight 12 months from date of service
				// Full Year of Service - The rate increase is Jan after the full year of Service. 
				Date serviceMonth = oli.ServiceDate.addMonths(i).toStartOfMonth();
				Integer yearOfServiceMonth = oli.ServiceDate.addMonths(12).month();

				if (rateIncreaseTerms == 'Anniversary') {		
						if (i > 12) { 
							// If Trip rate, get the number of trips based on selections on Opportunity Line Item
							if (oli.Monthly_or_Trip_Rate__c == 'Trip') {
								DaysWrapper dWrapper = getDaysInMonth(serviceMonth.year(),serviceMonth.month(),serviceMonth.day());
								Integer numberOfTripsInMonth = getTotalTripsInMonth(oli,dWrapper);
								rateIncreaseUnitPrice = rateIncreaseUnitPrice * numberOfTripsInMonth;
							}

							MCVStructure mcv1 = new MCVStructure(oli.Id,serviceMonth,rateIncreaseUnitPrice,true);
							mcv1.theOpportunityId = oli.OpportunityId;
							mcv1.accountName = opportunityMap.get(oli.OpportunityId).Account.Name;
							mcv1.productId   = pricebookEntryToProductMap.get(oli.PricebookEntryId).Id;
							mcv1.lineItem     = oli;
							mcvs.add(mcv1);

							// Compound Calculation update the rateIncrease
							if (Math.mod(i,12) == 0) {
								Integer termYear = i/12;
								rateIncreaseUnitPriceBuffer = rateIncreaseUnitPriceBuffer + (rateIncreaseUnitPriceBuffer * rateIncrease/100);
								rateIncreaseApplied = true;
							}
							// Skip into next term
							continue;
						}
				} else if (i > (12 + (12 - yearOfServiceMonth))) {
							
						// If Trip rate, get the number of trips based on selections on Opportunity Line Item
							if (oli.Monthly_or_Trip_Rate__c == 'Trip') {
								DaysWrapper dWrapper = getDaysInMonth(serviceMonth.year(),serviceMonth.month(),serviceMonth.day());
								Integer numberOfTripsInMonth = getTotalTripsInMonth(oli,dWrapper);
								rateIncreaseUnitPrice = rateIncreaseUnitPrice * numberOfTripsInMonth;
							}

							MCVStructure mcv1 = new MCVStructure(oli.Id,serviceMonth,rateIncreaseUnitPrice,true);
							mcv1.theOpportunityId = oli.OpportunityId;
							mcv1.accountName = opportunityMap.get(oli.OpportunityId).Account.Name;
							mcv1.productId   = pricebookEntryToProductMap.get(oli.PricebookEntryId).Id;
							mcv1.lineItem     = oli;
							mcvs.add(mcv1);
							
							// Compound Calculation, for 1st of Jan, the rate increase is applied 1 full year after the service
							// start date, so make sure the rate increase applies only after 2 terms. (1st term is already calculated
							// above)
							// Term year filler always ends on December. The next iteration is a January when the rate increase
							// needs to be applied.
							if (i == (termYearFiller + 12)) {
								rateIncreaseUnitPriceBuffer = rateIncreaseUnitPriceBuffer + (rateIncreaseUnitPriceBuffer * rateIncrease/100);
								rateIncreaseApplied = true;
								termYearFiller = termYearFiller + 12;
							}
							// Skip into next term
							continue;
				}


				// If Trip rate, get the number of trips based on selections on Opportunity Line Item
				if (oli.Monthly_or_Trip_Rate__c == 'Trip') {
					DaysWrapper dWrapper = getDaysInMonth(serviceMonth.year(),serviceMonth.month(),serviceMonth.day());
					Integer numberOfTripsInMonth = getTotalTripsInMonth(oli,dWrapper);
					unitPrice = unitPrice * numberOfTripsInMonth;
				}

				MCVStructure mcv1 = new MCVStructure(oli.Id,serviceMonth,unitPrice,false);
				mcv1.theOpportunityId = oli.OpportunityId;
				mcv1.accountName = opportunityMap.get(oli.OpportunityId).Account.Name;
				mcv1.productId   = pricebookEntryToProductMap.get(oli.PricebookEntryId).Id;
				mcv1.lineItem     = oli;
				mcvs.add(mcv1);
			}

		}

		createMCVs(mcvs,true); // Create the MCV Records

		return json.serializePretty(mcvs);

	}
    
    public static void calculateMcvAmountBluebeam(set<Id> olId){
        system.debug(olId);
        system.debug('inside function bluebeam');
        List<MCV_Line_Items__c> MLI=[select id,Discount__c,	MCV_Amount__c,Opportunity_Line_Item__c,Opportunity_Line_Item__r.UnitPrice  from MCV_Line_Items__c where Opportunity_Product_Id__c in:olId];
    	system.debug('mcv list'+MLI);  
        List<MCV_Line_Items__c> MLItoUpdate=new list<MCV_Line_Items__c>();
        for(MCV_Line_Items__c ml:MLI){
            if(ml.Discount__c==NULL)
            {
             Decimal disc= 0 * ml.MCV_Amount__c ;
            disc=disc/100;
            system.debug(disc);
            ml.MCV_Amount__c=ml.MCV_Amount__c- disc;
            system.debug(ml.MCV_Amount__c);
            MLItoUpdate.add(ml);
            }
            system.debug('inside for loop to update amount');
            Decimal disc=ml.Discount__c * ml.MCV_Amount__c ;
            disc=disc/100;
            system.debug(disc);
            ml.MCV_Amount__c=ml.MCV_Amount__c- disc;
            system.debug(ml.MCV_Amount__c);
            MLItoUpdate.add(ml);
        }
    update MLItoUpdate;
    }

	/**
	 * Delete the MCV's if the lineitems are deleted.
	 * @param lineItems Opportunity Line Items.
	 */
	public static void deleteMCVs(List<OpportunityLineItem> lineItems) {

		List<MCV_Line_Items__c> mcvLineItems = new List<MCV_Line_Items__c>();
        List<Opportunity> RCSOpptsToUpdate = new List<Opportunity>();
		
		Set<Id> lineItemIds = new Set<Id>();
        Set<Id> RCSOpptIds = new Set<Id>();
		
		for (OpportunityLineItem oli : lineItems) {
			lineItemIds.add(oli.Id);
            
		}

		mcvLineItems = [Select Id from MCV_Line_Items__c where Opportunity_Product_Id__c IN :lineItemIds];
        
        for (AggregateResult aggRes : [SELECT COUNT(ID) numRCS, OpportunityId
              FROM OpportunityLineItem
            	where Product2Id IN (select Id from Product2 where isActive =true and family IN ('Recyclers', 'CompuSafe'))
                 and Id IN :lineItemIds
					and OpportunityId not in (select Id from Opportunity where Has_RCS_Product__c = true)
              GROUP BY OpportunityId limit 200]) {
            
            Id OpportunityId = (Id) aggRes.get('OpportunityId');
            Integer numRCS = (Integer) aggRes.get('numRCS');
                  
            if (numRCS > 0)
                RCSOpptIds.add(OpportunityId);
        }
        
        if (RCSOpptIds.size() > 0)
        {
            RCSOpptsToUpdate = [Select Id, Has_RCS_Product__c from Opportunity where Id IN :RCSOpptIds];
            for (integer i=0;i<RCSOpptsToUpdate.size(); i++) {
                RCSOpptsToUpdate[i].Has_RCS_Product__c = true;
            }
            update RCSOpptsToUpdate;
        }

		delete mcvLineItems;

	}

	public static List<MCV_Line_Items__c> createMCVs(List<MCVStructure> mcvs, Boolean doInsert) {
		
		List<MCV_Line_Items__c> items = new List<MCV_Line_Items__c>();
		
		for (MCVStructure mcv : mcvs) {
			MCV_Line_Items__c lineItem = new MCV_Line_Items__c();
			lineItem.Date__c = mcv.theMonth;
			lineItem.MCV_Amount__c = mcv.mcvAmount;
			lineItem.Opportunity__c = mcv.theOpportunityId;
			lineItem.Opportunity_Product_Id__c = mcv.lineItem.Id;
			lineItem.Rate_Increase_Applied__c = mcv.hasRateIncreaseApplied;
			lineItem.Product__c = mcv.productId;
			lineItem.ATM_Deposit_Processing__c = mcv.lineItem.ATM_Deposit_Processing__c;
			lineItem.BDEX__c = mcv.lineItem.BDEX__c;
			lineItem.Brink_s_24x7_App__c = mcv.lineItem.Brink_s_24x7_App__c;
			lineItem.Cash_Forecasting__c = mcv.lineItem.Cash_Forecasting__c;
			lineItem.Cash_Vault_Services__c = mcv.lineItem.Cash_Vault_Services__c;
			lineItem.Cellular_Communication__c = mcv.lineItem.Cellular_Communication__c;
			lineItem.Cellular_Connectivity__c = mcv.lineItem.Cellular_Connectivity__c;
			lineItem.Check_Imaging__c = mcv.lineItem.Check_Imaging__c;
			lineItem.Coin_Processing__c = mcv.lineItem.Coin_Processing__c;
			lineItem.Coin__c = mcv.lineItem.Coin__c;
			lineItem.Conjunctive__c = mcv.lineItem.Conjunctive__c;
			lineItem.Customer_Success_Single_POC__c = mcv.lineItem.Customer_Success_Single_POC__c;
			lineItem.Daily_Credit_Bundle__c = mcv.lineItem.Daily_Credit_Bundle__c;
			lineItem.Daily_Credit__c = mcv.lineItem.Daily_Credit__c;
			lineItem.Device_Dashboard__c = mcv.lineItem.Device_Dashboard__c;
			lineItem.Enhanced_Service_Guarantee__c = mcv.lineItem.Enhanced_Service_Guarantee__c;
			lineItem.Envelope_Drop_Package__c = mcv.lineItem.Envelope_Drop_Package__c;
			lineItem.FI__c = mcv.lineItem.FI__c;
			lineItem.Inventory_Management__c = mcv.lineItem.Inventory_Management__c;
			lineItem.Location__c = mcv.lineItem.Location__c;
			lineItem.Monthly_or_Trip_Rate__c = mcv.lineItem.Monthly_or_Trip_Rate__c;
			lineItem.Retail__c = mcv.lineItem.Retail__c;
			lineItem.SmartDrop_Box__c = mcv.lineItem.SmartDrop_Box__c;
			lineItem.Standard_Warranty__c = mcv.lineItem.Standard_Warranty__c;
			lineItem.Trip_Rate_if_applicable__c = mcv.lineItem.Trip_Rate_if_applicable__c;
			lineItem.Web_based_Reporting_iInfo__c = mcv.lineItem.Web_based_Reporting_iInfo__c;
            lineItem.Upfront_Fee_Product__c = mcv.upfrontFeeProduct;
			items.add(lineItem);
		}
		
		//system.debug(items);

		if (doInsert)
			insert items;
		
		return items; 
				
	}

	public static Integer getTotalTripsInMonth(OpportunityLineItem oli, DaysWrapper dWrapper) {
		
		Integer totalTrips = 0;
		
		if (oli.Frequency__c == 'Monthly') {
				totalTrips = oli.SUN__c != null && oli.SUN__c && dWrapper.numberOfSundays > 0 ? totalTrips + 1 : totalTrips;
				totalTrips = oli.MON__c != null && oli.MON__c && dWrapper.numberOfMondays > 0 ? totalTrips + 1 : totalTrips;
				totalTrips = oli.TUES__c != null && oli.TUES__c && dWrapper.numberOfTuesdays > 0 ? totalTrips + 1 : totalTrips;
				totalTrips = oli.WED__c != null && oli.WED__c && dWrapper.numberOfWednesdays > 0 ? totalTrips + 1: totalTrips;
				totalTrips = oli.THURS__c != null && oli.THURS__c && dWrapper.numberOfThursdays > 0 ? totalTrips + 1: totalTrips;
				totalTrips = oli.FRI__c != null && oli.FRI__c && dWrapper.numberOfFridays > 0 ? totalTrips + 1 : totalTrips;
				totalTrips = oli.SAT__c != null && oli.SAT__c && dWrapper.numberOfSaturdays > 0 ? totalTrips + 1 : totalTrips;				
			} else {
				totalTrips = oli.SUN__c != null && oli.SUN__c ? totalTrips + dWrapper.numberOfSundays : totalTrips;
				totalTrips = oli.MON__c != null && oli.MON__c ? totalTrips + dWrapper.numberOfMondays : totalTrips;
				totalTrips = oli.TUES__c != null && oli.TUES__c ? totalTrips + dWrapper.numberOfTuesdays : totalTrips;
				totalTrips = oli.WED__c != null && oli.WED__c ? totalTrips + dWrapper.numberOfWednesdays : totalTrips;
				totalTrips = oli.THURS__c != null && oli.THURS__c ? totalTrips + dWrapper.numberOfThursdays : totalTrips;
				totalTrips = oli.FRI__c != null && oli.FRI__c ? totalTrips + dWrapper.numberOfFridays : totalTrips;
				totalTrips = oli.SAT__c != null && oli.SAT__c ? totalTrips + dWrapper.numberOfSaturdays : totalTrips;			
			}

			if (oli.Frequency__c == 'EOW')
				totalTrips = totalTrips/2;
		

		return totalTrips;
	}

	public static DaysWrapper getDaysInMonth(Integer year, Integer month, Integer dayOfMonth) {
		
		if (dayOfMonth == null)
			dayOfMonth = 1;

		DaysWrapper dWrapper = new DaysWrapper(year, month, dayOfMonth);
		Datetime monthStartDate = Datetime.newInstance(year, month, dayOfMonth);
		
		while (month == monthStartDate.month()) {	
		
			String day = monthStartDate.format('EEE');
			
			if (day == 'SUN')
				dWrapper.numberOfSundays += 1;
			if (day == 'MON')
				dWrapper.numberOfMondays += 1;
			if (day == 'TUE')
				dWrapper.numberOfTuesdays += 1;
			if (day == 'WED')
				dWrapper.numberOfWednesdays += 1;
			if (day == 'THU')
				dWrapper.numberOfThursdays += 1;
			if (day == 'FRI')
				dWrapper.numberOfFridays += 1;					
			if (day == 'SAT')
				dWrapper.numberOfSaturdays += 1;

			monthStartDate = monthStartDate.addDays(1);	
		}						

		return dWrapper;	
	}


	public class DaysWrapper {
		
		public Integer year;
		public Integer month;
		public Integer dayOfMonth;
		public Integer numberOfSundays;
		public Integer numberOfMondays;
		public Integer numberOfTuesdays;
		public Integer numberOfWednesdays;
		public Integer numberOfThursdays;
		public Integer numberOfFridays;
		public Integer numberOfSaturdays;

		public DaysWrapper(Integer year, Integer month, Integer dayOfMonth) {
			this.year = year;
			this.month = month; 
			this.dayOfMonth = dayOfMonth;
			this.numberOfSundays = 0;
			this.numberOfMondays = 0;
			this.numberOfTuesdays = 0;
			this.numberOfWednesdays = 0;
			this.numberOfThursdays = 0;
			this.numberOfFridays = 0;
			this.numberOfSaturdays = 0;
		}
	}

	public class MCVStructure {
		public OpportunityLineItem lineItem     {get;set;}
		public Id theOpportunityLineItemId 		{get;set;}
		public Id theOpportunityId 				{get;set;}
		public String accountName				{get;set;}
		public Id productId						{get;set;}
		public Date theMonth 					{get;set;}
		public Decimal mcvAmount 				{get;set;}
		public Boolean hasRateIncreaseApplied 	{get;set;}
        public Boolean upfrontFeeProduct	 	{get;set;}

		public MCVStructure (Id theOpportunityLineItemId, Date theMonth, Decimal mcvAmount, Boolean hasRateIncreaseApplied) {
			this.theOpportunityLineItemId = theOpportunityLineItemId;
			this.theMonth = theMonth;
			this.mcvAmount = mcvAmount;
			this.hasRateIncreaseApplied = hasRateIncreaseApplied;
            this.upfrontFeeProduct = false;
		}
	}

}
 
Apex Trigger:
/**
 * Created by Kartik (NeuraFlash)
 * Apex Trigger to create MCV line items
 */
trigger OpportunityProductTrigger on OpportunityLineItem (after insert, after update, before delete) {
    //system.debug('inside trigger, loop ahead');
    set<id> OLID=new set<Id>();
    integer i=0;
    for(OpportunityLineItem Oli:trigger.new ){
        
        if(Oli.ProductCode=='Blubeem'&& oli.UnitPrice != null){
            system.debug('inside trigger bluebeem product');
            OLID.add(Oli.Id);
            i=1;
        }
    }
    
	
    if (Trigger.isInsert && Trigger.isAfter) {
          
        // Call the service class to create MCV Records
        OpportunityProductService.calculateMCVs(trigger.new);
        if(i==1){
        system.debug('calling function for blue beam');
        OpportunityProductService.calculateMcvAmountBluebeam(OLID);}
    system.debug('inside After insert');
        system.debug(trigger.new);
    } 
    
    else if (Trigger.isUpdate && Trigger.isAfter) {
         
        // Delete the existing MCVs
        OpportunityProductService.deleteMCVs(trigger.new);
        // Create new ones
       
        OpportunityProductService.calculateMCVs(trigger.new);
         if(i==1){
        system.debug('calling function for blue beam');
        OpportunityProductService.calculateMcvAmountBluebeam(OLID);
          }
    system.debug('inside After update');
    }
    
     
    else if (Trigger.isDelete) {
        system.debug('inside Delete');
        OpportunityProductService.deleteMCVs(trigger.old);
    }
    
   /* if(i==1){
        system.debug('calling function for blue beam');
        OpportunityProductService.calculateMcvAmountBluebeam(OLID);}*/
    
    }
 
New Method Implemented :
public static void calculateMcvAmountBluebeam(set<Id> olId){
        system.debug(olId);
        system.debug('inside function bluebeam');
        List<MCV_Line_Items__c> MLI=[select id,Discount__c,	MCV_Amount__c,Opportunity_Line_Item__c,Opportunity_Line_Item__r.UnitPrice  from MCV_Line_Items__c where Opportunity_Product_Id__c in:olId];
    	system.debug('mcv list'+MLI);  
        List<MCV_Line_Items__c> MLItoUpdate=new list<MCV_Line_Items__c>();
        for(MCV_Line_Items__c ml:MLI){
            if(ml.Discount__c==NULL)
            {
             Decimal disc= 0 * ml.MCV_Amount__c ;
            disc=disc/100;
            system.debug(disc);
            ml.MCV_Amount__c=ml.MCV_Amount__c- disc;
            system.debug(ml.MCV_Amount__c);
            MLItoUpdate.add(ml);
            }
            system.debug('inside for loop to update amount');
            Decimal disc=ml.Discount__c * ml.MCV_Amount__c ;
            disc=disc/100;
            system.debug(disc);
            ml.MCV_Amount__c=ml.MCV_Amount__c- disc;
            system.debug(ml.MCV_Amount__c);
            MLItoUpdate.add(ml);
        }
    update MLItoUpdate;
    }

Please help me with trigger to calculate  to calculate dicount for mcv amount only for blubeem products , for create , update and delete .. The prorate should work .
VinayVinay (Salesforce Developers) 
Hi Mohini,

You can reachout to accelerate team who can help your implementation request if you have premier support.

https://help.salesforce.com/s/articleView?id=000387492&type=1

Thanks,