I don't quite understand this situation and I wonder, if somebody knows where is the problem.
I' assigning in loop object as a key and simple number as his value:
Map<QuoteLineItem, Integer> mapa = new Map<QuoteLineItem, Integer>();
for (QuoteLineItem a : [SELECT Id FROM QuoteLineItem]) {
mapa.put(a, 1);
}
The query returns two objects: QuoteLineItem:{Id=0QL290000000NMjGAM}
and QuoteLineItem:{Id=0QL290000000NMeGAM}
, but map contains just:
{QuoteLineItem:{Id=0QL290000000NMjGAM}=1}
When i query also for description field, the map contains both records:
{
QuoteLineItem:{Id=0QL290000000NMjGAM, Description=discount}=1,
QuoteLineItem:{Id=0QL290000000NMeGAM, Description=test apptus}=1
}
I'm aware, that key field is hashed, but these two records have different Ids, so they are not the same. And still, if we put same key into map, then the old key value should be rewritten with new value.
Map
is really a bad idea as mentioned here.Try to use QuoteLineItem'sId
as key