I have this below code which is throwing error. Can anyone help what is going wrong.


Method does not exist or incorrect signature: void put(OpportunityLineItem) from the type Map


Map<Id,OpportunityLineItem> mapOli = new Map<Id,OpportunityLineItem> ();
for(OpportunityLineItemSchedule sch: lstLineItemSchedule) {
    If(mapOli.get(sch.OpportunityLineItemId) == null) {
        Decimal oliUniPrice = oliIDToSalesPriceMap.get(sch.OpportunityLineItemId);
        mapOli.put(new OpportunityLineItem(Id=sch.Id,UnitPrice =oliUniPrice));

closed as off-topic by Pranay Jaiswal, glls, Mohith Shrivastava, Raul, Christian Deckert Dec 21 '18 at 7:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Mohith Shrivastava, Raul, Christian Deckert
If this question can be reworded to fit the rules in the help center, please edit the question.


A Map.put() expects a <key, value> pair whenever you add an element in it. The signature for the method is: public Object put(Object key, Object value).

In your case, you are missing the key to be added in the Map and thus the error.

mapOli.put(new OpportunityLineItem(Id=oLisch.Id,UnitPrice =oliUniPrice));

You will need to change this to as below:

mapOli.put(<key- whatever you choose>, new OpportunityLineItem(Id=oLisch.Id,UnitPrice =oliUniPrice));

Not the answer you're looking for? Browse other questions tagged or ask your own question.