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
Nevin O'Regan 3Nevin O'Regan 3 

Update Field Values In Parent Object

Hi guys,

I have created 12 custom number fields in the OppLineItem, each labeled a month of the year. I have also created a custom formula text field in the OppLineItemSchedule object called Month which defines the month based on the scheduled date.
I am trying to create a trigger to map the Quantity value from the related OppLineItemSchedule record to the relevant OppLineItem Month field. I have created the below trigger but the issue is that it is populating every Month field on the OppLineItem with a value even if there is not a related OppLineItemSch Quantity. 

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> MapMonths = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         MapMonths.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c, 
                                            February__c, 
                                            March__c, 
                                            April__c, 
                                            May__c, 
                                            June__c, 
                                            July__c, 
                                            August__c, 
                                            September__c, 
                                            October__c, 
                                            November__c,
                                            December__c From OpportunityLineItem Where Id IN :MapMonths.Keyset()])
    {
        if(MapMonths.containsKey(oli.id))
        {
            OppLineItemList.add(new OpportunityLineItem(Id = oli.id, January__c=MapMonths.get(oli.id), 
                                                                     February__c=MapMonths.get(oli.id),
                                                                        March__c=MapMonths.get(oli.id), 
                                                                     April__c=MapMonths.get(oli.id),
                                                                     May__c=MapMonths.get(oli.id),
                                                                     June__c=MapMonths.get(oli.id),
                                                                     July__c=MapMonths.get(oli.id),
                                                                     August__c=MapMonths.get(oli.id),
                                                                     September__c=MapMonths.get(oli.id),
                                                                     October__c=MapMonths.get(oli.id),
                                                                     November__c=MapMonths.get(oli.id),
                                                                     December__c=MapMonths.get(oli.id)));
                                                                                    
        }
    }
    update OppLineItemList;
}
Best Answer chosen by Nevin O'Regan 3
Boss CoffeeBoss Coffee
Try the following.
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    
    // UPDATED: Must handle multiple children for a single parent
    // Instead of a single OpportunityLineItem, hold a list of them
    Map<Id,List<OpportunityLineItemSchedule>> MapMonths = new Map<Id, List<OpportunityLineItemSchedule>>();
    
    // Have a temp list ready for looping
    List<OpportunityLineItemSchedule> tempOlisList;
    
    // Now populate the months map
    for(OpportunityLineItemSchedule sch : trigger.new) {
        // Check if the map already has an entry for the parent Id (key)
        if(MapMonths.containsKey(sch.OpportunityLineItemId)) {
            // If it does, then update the list with the new value (so it will not override the previous value)
            tempOlisList = MapMonths.get(sch.OpportunityLineItemId);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        } else {
            // Otherwise, we will create a new entry in the map with a list value of just the current iteration's OLIS
            tempOlisList = new List<OpportunityLineItemSchedule);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        }
    }

    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            
            // UPDATE: Because we have a list of children now, we will need to loop through all of them to assign values to each month before moving on to the next Opportunity Line Item
            // Create a for loop to go through the list of children
            for(OpportunityItemListSchedule olis : MapMonths.get(oli.id)) {
                
                // Create a switch statement to check what value is the Month
                switch on olis.Month__c {
                    // If the opportunity line item schedule's Month field was January
                    when 'January' {
                        // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                        oli.January__c = olis.Quantity;
                    }
                    when 'February' {
                        oli.February__c = olis.Quantity;
                    }
                    when 'March' {
                        oli.March__c = olis.Quantity;
                    }
                    when 'April' {
                        oli.April__c = olis.Quantity;
                    }
                    when 'May' {
                        oli.May__c = olis.Quantity;
                    }
                    when 'June' {
                        oli.June__c = olis.Quantity;
                    }
                    when 'July' {
                        oli.July__c = olis.Quantity;
                    }
                    when 'August' {
                        oli.August__c = olis.Quantity;
                    }
                    when 'September' {
                        oli.September__c = olis.Quantity;
                    }
                    when 'October' {
                        oli.October__c = olis.Quantity;
                    }
                    when 'November' {
                        oli.November__c = olis.Quantity;
                    }
                    when 'December' {
                        oli.December__c = olis.Quantity;
                    }
                    // If it did not find any matches
                    when else {
                        // EDIT: do not put anything here for now
                        // You can leave this empty or put something in here to handle cases where the Month field is NOT the name of the month
                        // e.g. Month field was for some reason populated with 'Apple'
                    }
                }
            }
            OppLineItemList.add(oli);
        }
    }
    update OppLineItemList;
}

All Answers

Boss CoffeeBoss Coffee
The following block from your code assigns all months the same value. You will need to check which month the OppLineItemSchedule is referring to, then only execute one of the lines for assigning quantity.
 if(MapMonths.containsKey(oli.id))
        {
            OppLineItemList.add(new OpportunityLineItem(Id = oli.id, January__c=MapMonths.get(oli.id), 
                                                                     February__c=MapMonths.get(oli.id),
                                                                        March__c=MapMonths.get(oli.id), 
                                                                     April__c=MapMonths.get(oli.id),
                                                                     May__c=MapMonths.get(oli.id),
                                                                     June__c=MapMonths.get(oli.id),
                                                                     July__c=MapMonths.get(oli.id),
                                                                     August__c=MapMonths.get(oli.id),
                                                                     September__c=MapMonths.get(oli.id),
                                                                     October__c=MapMonths.get(oli.id),
                                                                     November__c=MapMonths.get(oli.id),
                                                                     December__c=MapMonths.get(oli.id)));
                                                                                    
        }
Nevin O'Regan 3Nevin O'Regan 3
Thanks Boss Coffee, would you have any example of how this would look? Sorry but I'm only starting out with writing triggers. 
Boss CoffeeBoss Coffee
First thing you'll need access to is the OppLineItemSchedule field, Month. In the following, I made changes to your MapMonths to include the entire OpportunityLineItemSchedule instead of just the quantity.
Map<Id,OpportunityLineItemSchedule> MapMonths = new Map<Id, OpportunityLineItemSchedule>();    
for(OpportunityLineItemSchedule sch : trigger.new) {
  MapMonths.put(sch.OpportunityLineItemId, sch);
}
Now in your loop, I'll show an example with three months.
// Create a temp before the for loop to hold a value while looping
OpportunityLineItemSchedule tempOLIS;

// Your for loop code that grabs all the opportuniy line items
// Then, the following is the updated if statement inside your for loop
if(MapMonths.containsKey(oli.id)) {
  // Get the opportunity line item schedule record
  tempOLIS = MapMonths.get(oli.id);
  // Create a switch statement to check what value is the Month
  switch on tempOLIS.Month {
    // If the opportunity line item schedule's Month field was January
    when 'January' {
      // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
      oli.January__c = tempOLIS.Quantity;
    }
    when 'February' {
      oli.February__c = tempOLIS.Quantity;
    }
    when 'March' {
      oli.March__c = tempOLIS.Quantity;
    }
    // If it did not find any matches
    when else {
      // Then do whatever logic here, for now I print a system debug
      System.debug('Month text was invalid.');
    }
  }
}
Nevin O'Regan 3Nevin O'Regan 3
Thanks very much Boss Coffee. 
Nevin O'Regan 3Nevin O'Regan 3
Hi Jun,

I have applied your code but it is not firing. It's not updating the fields on the OpportunityLineItem. This is the code that I have. 

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,OpportunityLineItemSchedule> MapMonths = new Map<Id, OpportunityLineItemSchedule>();
    
    for(OpportunityLineItemSchedule sch : trigger.new) {
  MapMonths.put(sch.OpportunityLineItemId, sch);
}
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
// Create a temp before the for loop to hold a value while looping
OpportunityLineItemSchedule tempOLIS;
// Your for loop code that grabs all the opportuniy line items
    for(OpportunityLineItem oli:[Select id, January__c,
                                            February__c, 
                                            March__c, 
                                            April__c, 
                                            May__c, 
                                            June__c, 
                                            July__c, 
                                            August__c, 
                                            September__c, 
                                            October__c, 
                                            November__c,
                                            December__c From OpportunityLineItem Where Id IN :MapMonths.Keyset()])
// Then, the following is the updated if statement inside your for loop
if(MapMonths.containsKey(oli.id)) {
  // Get the opportunity line item schedule record
  tempOLIS = MapMonths.get(oli.id);
  // Create a switch statement to check what value is the Month
  switch on tempOLIS.Month__c {
    // If the opportunity line item schedule's Month field was January
    when 'January' {
      // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
      oli.January__c = tempOLIS.Quantity;
    }
    when 'February' {
      oli.February__c = tempOLIS.Quantity;
    }
    when 'March' {
      oli.March__c = tempOLIS.Quantity;
    }
    when 'April' {
      oli.April__c = tempOLIS.Quantity;
    }
    when 'May' {
      oli.May__c = tempOLIS.Quantity;
    }
    when 'June' {
      oli.June__c = tempOLIS.Quantity;
    }
    when 'July' {
      oli.July__c = tempOLIS.Quantity;
    }
    when 'August' {
      oli.August__c = tempOLIS.Quantity;
    }
    when 'September' {
      oli.September__c = tempOLIS.Quantity;
    }
    when 'October' {
      oli.October__c = tempOLIS.Quantity;
    }
    when 'November' {
      oli.November__c = tempOLIS.Quantity;
    }
    when 'December' {
      oli.December__c = tempOLIS.Quantity;
    }
    // If it did not find any matches
    when else {
      // Then do whatever logic here, for now I print a system debug
      update OppLineItemList;
    }
  }
}
}
Boss CoffeeBoss Coffee
Add the following line to each of the cases. It adds the updated opportunity line item to the list for updating. Example shown below.
when 'January' {
  // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
  oli.January__c = tempOLIS.Quantity;
  OppLineItemList.add(oli);
}
// same thing for the rest
Then, move your DML statement outside of the switch statement. Place it at the very end so it will update the entire list at once.
// Your for loop
for {
  // Adds to your list of opportunity line items
}

update OppLineItemList;
Boss CoffeeBoss Coffee
You may also add to the list at the end of the if statement.
if(//) {
  tempOLIS = MapMonths.get(oli.id);
  switch {
    // switch logic
  }
  // before the end of the if, add to the list
  OppLineItemList.add(oli);
}

 
Nevin O'Regan 3Nevin O'Regan 3
Hi Jun,

Below is what I have done. I think I have placed your suggested changes in the correct places but it is not working. 

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,OpportunityLineItemSchedule> MapMonths = new Map<Id, OpportunityLineItemSchedule>();
    

// Create a temp before the for loop to hold a value while looping
OpportunityLineItemSchedule tempOLIS;
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[Select id, January__c,
                                            February__c, 
                                            March__c, 
                                            April__c, 
                                            May__c, 
                                            June__c, 
                                            July__c, 
                                            August__c, 
                                            September__c, 
                                            October__c, 
                                            November__c,
                                            December__c From OpportunityLineItem Where Id IN :MapMonths.Keyset()])
// Then, the following is the updated if statement inside your for loop
if(MapMonths.containsKey(oli.id)) {
  // Get the opportunity line item schedule record
  tempOLIS = MapMonths.get(oli.id);
  // Create a switch statement to check what value is the Month
  switch on tempOLIS.Month__c {
    // If the opportunity line item schedule's Month field was January
    when 'January' {
      // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
      oli.January__c = tempOLIS.Quantity;
    }
    when 'February' {
      oli.February__c = tempOLIS.Quantity;
    }
    when 'March' {
      oli.March__c = tempOLIS.Quantity;
    }
    when 'April' {
      oli.April__c = tempOLIS.Quantity;
    }
    when 'May' {
      oli.May__c = tempOLIS.Quantity;
    }
    when 'June' {
      oli.June__c = tempOLIS.Quantity;
    }
    when 'July' {
      oli.July__c = tempOLIS.Quantity;
    }
    when 'August' {
      oli.August__c = tempOLIS.Quantity;
    }
    when 'September' {
      oli.September__c = tempOLIS.Quantity;
    }
    when 'October' {
      oli.October__c = tempOLIS.Quantity;
    }
    when 'November' {
      oli.November__c = tempOLIS.Quantity;
    }
    when 'December' {
      oli.December__c = tempOLIS.Quantity;
    }
    // If it did not find any matches
    when else {
        // Your for loop code that grabs all the opportuniy line items
    for(OpportunityLineItemSchedule sch : trigger.new) {
  MapMonths.put(sch.OpportunityLineItemId, sch);
}
      // Then do whatever logic here, for now I print a system debug
      update OppLineItemList;
    }
  }
    OppLineItemList.add(oli);

}
}
Nevin O'Regan 3Nevin O'Regan 3
Just something I have spotted  in your post above and I want to double check that the code is mapping the fields in the right direction.

when 'January' { // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity oli.January__c = tempOLIS.Quantity;   OppLineItemList.add(oli); }
// same thing for the rest


The Opportunity Line Item Schedule Quanity  will be mapped to the Opportunity Line Item January field right?
Boss CoffeeBoss Coffee
Yes, that was a mistake on my part. I meant to say that the Opportunity Line Item January field will be populated with the Opportunity Line Item Schedule Quantity field value.

As for your current code, there are a few misplaced lines.
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,OpportunityLineItemSchedule> MapMonths = new Map<Id, OpportunityLineItemSchedule>();
    
    
    // Create a temp before the for loop to hold a value while looping
    OpportunityLineItemSchedule tempOLIS;
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            // Get the opportunity line item schedule record
            tempOLIS = MapMonths.get(oli.id);
            // Create a switch statement to check what value is the Month
            switch on tempOLIS.Month__c {
                // If the opportunity line item schedule's Month field was January
                when 'January' {
                    // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                    oli.January__c = tempOLIS.Quantity;
                }
                when 'February' {
                    oli.February__c = tempOLIS.Quantity;
                }
                when 'March' {
                    oli.March__c = tempOLIS.Quantity;
                }
                when 'April' {
                    oli.April__c = tempOLIS.Quantity;
                }
                when 'May' {
                    oli.May__c = tempOLIS.Quantity;
                }
                when 'June' {
                    oli.June__c = tempOLIS.Quantity;
                }
                when 'July' {
                    oli.July__c = tempOLIS.Quantity;
                }
                when 'August' {
                    oli.August__c = tempOLIS.Quantity;
                }
                when 'September' {
                    oli.September__c = tempOLIS.Quantity;
                }
                when 'October' {
                    oli.October__c = tempOLIS.Quantity;
                }
                when 'November' {
                    oli.November__c = tempOLIS.Quantity;
                }
                when 'December' {
                    oli.December__c = tempOLIS.Quantity;
                }
                // If it did not find any matches
                when else {
                    // EDIT: do not put anything here for now
                }
            }
            OppLineItemList.add(oli);
        }
    }
    // EDIT: Update the opportunity item list after the for loop is done
    update OppLineItemList;
}

 
Boss CoffeeBoss Coffee
Hold on, I caught a few more missing lines of code that was in the initial post.
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,OpportunityLineItemSchedule> MapMonths = new Map<Id, OpportunityLineItemSchedule>();
    // MISSING FOR LOOP to populate the ids
    for(OpportunityLineItemSchedule sch : trigger.new) {
        MapMonths.put(sch.OpportunityLineItemId, sch);
    }
    
    // Create a temp before the for loop to hold a value while looping
    OpportunityLineItemSchedule tempOLIS;
    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            // Get the opportunity line item schedule record
            tempOLIS = MapMonths.get(oli.id);
            // Create a switch statement to check what value is the Month
            switch on tempOLIS.Month__c {
                // If the opportunity line item schedule's Month field was January
                when 'January' {
                    // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                    oli.January__c = tempOLIS.Quantity;
                }
                when 'February' {
                    oli.February__c = tempOLIS.Quantity;
                }
                when 'March' {
                    oli.March__c = tempOLIS.Quantity;
                }
                when 'April' {
                    oli.April__c = tempOLIS.Quantity;
                }
                when 'May' {
                    oli.May__c = tempOLIS.Quantity;
                }
                when 'June' {
                    oli.June__c = tempOLIS.Quantity;
                }
                when 'July' {
                    oli.July__c = tempOLIS.Quantity;
                }
                when 'August' {
                    oli.August__c = tempOLIS.Quantity;
                }
                when 'September' {
                    oli.September__c = tempOLIS.Quantity;
                }
                when 'October' {
                    oli.October__c = tempOLIS.Quantity;
                }
                when 'November' {
                    oli.November__c = tempOLIS.Quantity;
                }
                when 'December' {
                    oli.December__c = tempOLIS.Quantity;
                }
                // If it did not find any matches
                when else {
                    // EDIT: do not put anything here for now
                }
            }
            OppLineItemList.add(oli);
        }
    }
    // EDIT: Update the opportunity item list after the for loop is done
    update OppLineItemList;
}
Nevin O'Regan 3Nevin O'Regan 3
Thanks Jun,

I have updated the code and the results seem a bit weird. The only field that is updating is May__c, all of the other fields remain blank. 
Boss CoffeeBoss Coffee
After checking the Opportunity Line Item Schedule fields, what months should be populated for those particular Opportunity Line Items?
Nevin O'Regan 3Nevin O'Regan 3
Installment Period = Monthly
Number Of Installments = 12
Schedule Type = Divided Amount Into Multiple Installments

So there should be a value added to each of the "Month" fields in the Opportunity Line Item.
Boss CoffeeBoss Coffee
A single Opportunity Line Item Schedule has a single Month field, correct? And the quantity on that record maps to that particular Month on the parent Opportunity Line Item?

Am I right to assume that you have twelve Opportunity Line Item Schedule records per Opportunity Line Item if that is the case?
Nevin O'Regan 3Nevin O'Regan 3
Yes a single Opportunity Line Item Schedule has a single Month field and yes I have twelve Opportunity Line Item Schedules records per Opportunity Line Item for this case.  

OpportunityLineSchedule Sample - Month = Oct 
User-added image

OpportunityLineItem - Oct is blank but it should show the Quantity as per above. It does show the Quantity for May though
User-added image
Boss CoffeeBoss Coffee
In that case, you will need to change the logic to handle all of the children (assuming there is only one record per month) that looks up to an Opportunity Line Item. This can be done by setting the MapMonths to hold the parent Id (of Opportunity Line Item) and a list of all the children (Opportunity Line Item Schedule). The reason why it is only updating one Month is because the way the MapMonths is currently being populated. Because there may be multiple entries of Opportunity Line Item Schedule that look up to the same Opportunity LIne Item, the same Id is put into the Map multiple times, and only the last entry will be read (only the last Opportunity Line Item Schedule will be in the value, in this case it seems to be May).

Give me a bit while I update the code to reflect the changes that need to be made.
Nevin O'Regan 3Nevin O'Regan 3
Thanks Jun. 
Boss CoffeeBoss Coffee
Try the following.
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    
    // UPDATED: Must handle multiple children for a single parent
    // Instead of a single OpportunityLineItem, hold a list of them
    Map<Id,List<OpportunityLineItemSchedule>> MapMonths = new Map<Id, List<OpportunityLineItemSchedule>>();
    
    // Have a temp list ready for looping
    List<OpportunityLineItemSchedule> tempOlisList;
    
    // Now populate the months map
    for(OpportunityLineItemSchedule sch : trigger.new) {
        // Check if the map already has an entry for the parent Id (key)
        if(MapMonths.containsKey(sch.OpportunityLineItemId)) {
            // If it does, then update the list with the new value (so it will not override the previous value)
            tempOlisList = MapMonths.get(sch.OpportunityLineItemId);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        } else {
            // Otherwise, we will create a new entry in the map with a list value of just the current iteration's OLIS
            tempOlisList = new List<OpportunityLineItemSchedule);
            tempOlisList.add(sch);
            MapMonths.put(sch.OpportunityLineItemId, tempOlisList);
        }
    }

    List<OpportunityLineItem> OppLineItemList = new List<OpportunityLineItem>();
    for(OpportunityLineItem oli:[
        Select id, January__c,February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c,December__c 
        From OpportunityLineItem 
        Where Id IN :MapMonths.Keyset()
    ]) {
        // Then, the following is the updated if statement inside your for loop
        if(MapMonths.containsKey(oli.id)) {
            
            // UPDATE: Because we have a list of children now, we will need to loop through all of them to assign values to each month before moving on to the next Opportunity Line Item
            // Create a for loop to go through the list of children
            for(OpportunityItemListSchedule olis : MapMonths.get(oli.id)) {
                
                // Create a switch statement to check what value is the Month
                switch on olis.Month__c {
                    // If the opportunity line item schedule's Month field was January
                    when 'January' {
                        // Then assign the opportunity line item's January field to the opportunity line item schedule's quantity
                        oli.January__c = olis.Quantity;
                    }
                    when 'February' {
                        oli.February__c = olis.Quantity;
                    }
                    when 'March' {
                        oli.March__c = olis.Quantity;
                    }
                    when 'April' {
                        oli.April__c = olis.Quantity;
                    }
                    when 'May' {
                        oli.May__c = olis.Quantity;
                    }
                    when 'June' {
                        oli.June__c = olis.Quantity;
                    }
                    when 'July' {
                        oli.July__c = olis.Quantity;
                    }
                    when 'August' {
                        oli.August__c = olis.Quantity;
                    }
                    when 'September' {
                        oli.September__c = olis.Quantity;
                    }
                    when 'October' {
                        oli.October__c = olis.Quantity;
                    }
                    when 'November' {
                        oli.November__c = olis.Quantity;
                    }
                    when 'December' {
                        oli.December__c = olis.Quantity;
                    }
                    // If it did not find any matches
                    when else {
                        // EDIT: do not put anything here for now
                        // You can leave this empty or put something in here to handle cases where the Month field is NOT the name of the month
                        // e.g. Month field was for some reason populated with 'Apple'
                    }
                }
            }
            OppLineItemList.add(oli);
        }
    }
    update OppLineItemList;
}
This was selected as the best answer
Nevin O'Regan 3Nevin O'Regan 3
Thanks Jun,

I'm getting this error on line 20. 

Expecting '>' but was: ')'
Nevin O'Regan 3Nevin O'Regan 3
Is this correct

tempOlisList = new List<OpportunityLineItemSchedule>();?
Nevin O'Regan 3Nevin O'Regan 3
thanks very much Jun for all of your help with this. 
Boss CoffeeBoss Coffee
Glad to hear it's working!
Nevin O'Regan 3Nevin O'Regan 3
Hi Jun,

I have found a bug with this code. If I delete the schedule the values in the OpportunityLineItem remains. Is there a way to show blank values in the OpportunityLineItem fields if the related schedules are deleted or removed. They are updating if I change the values in the OpporunityLineItemSchedule but the are not updating to a blank value if I delete the related schedule.