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 

Method does not exist or incorrect signature: void put(Id, Decimal) from the type Map<Id,Integer>

Hi guys,

I am relatively new to writing triggers and I am running into an issue with one that I am currently working on. 

I would like to update custom fields in the OpportunityLineItem object with the value from the OpportunityLineItemSchedule.Quantity field. I have 12 custom fields in the OpportunityLineItem for each month of the year, Jan to Dec.

Here is the code that I have so far but I am running into an error "Method does not exist or incorrect signature: void put(Id, Decimal) from the type Map<Id,Integer>" on Line 6.

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new)
    {
        OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, sch.Quantity);
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}

 
Best Answer chosen by Nevin O'Regan 3
MKRMKR
Hi,

Try to use the following with type conversion (Integer.valueOf):
 
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}

Regards,
MKR​​​​​​​

All Answers

MKRMKR
Hi,

Try to use the following with type conversion (Integer.valueOf):
 
trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}

Regards,
MKR​​​​​​​
This was selected as the best answer
Nevin O'Regan 3Nevin O'Regan 3
Thanks MKR this has worked. I'm trying to more than one field e.g. Jan, Feb, Mar, Apr etc. 
I have a custom formula field called Month__c outlines which month of the year the OppLineSch record sits based on the Schedule Date field. So if the Schedule Date field is 01/02/2019 then Month__c = February. 

The below code doesn't fire of me. I get an error message "MapMontsOnSchedule: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 00k23000003ubsxAAA Trigger.MapMontsOnSchedule: line 18, column 1'

trigger MapMontsOnSchedule on OpportunityLineItemSchedule (after insert, before update) {
    Map<Id,Integer> OpportunityLineItemIdwithOpportunityLineItemScheduleField = new Map<Id, Integer>();
 
    for(OpportunityLineItemSchedule sch:trigger.new) {
         OpportunityLineItemIdwithOpportunityLineItemScheduleField.put(sch.OpportunityLineItemId, Integer.valueOf(sch.Quantity));
    }
 
    List<OpportunityLineItem> listUpdatedOpportunityLineItem = new List<OpportunityLineItem>();
 
    for(OpportunityLineItem oli:[Select id, January__c, February__c From OpportunityLineItem Where Id IN :OpportunityLineItemIdwithOpportunityLineItemScheduleField.Keyset()])
    {
        if(OpportunityLineItemIdwithOpportunityLineItemScheduleField.containsKey(oli.id))
        {
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, January__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
            listUpdatedOpportunityLineItem.add(new OpportunityLineItem(Id = oli.id, February__c=OpportunityLineItemIdwithOpportunityLineItemScheduleField.get(oli.id)));
        }
    }
    update listUpdatedOpportunityLineItem;
}
tulasi tayertulasi tayer
Great. It's working nice. And also am trying to add more fields...
Do you know which is the Best IAS Coaching Institutions in delhi (https://www.plagiary.org/best-ias-coaching-institutions-delhi/)