Are sObjects supported as the keys for Maps?
I thought they were, but it appears that any subsequent changes to the key sObject break the mapping to the value.
This might be better shown with an anonymous apex example (API v27.0).
Map<OpportunityLineItem, string> testMap = new Map<OpportunityLineItem, string>();
OpportunityLineItem testOli = new OpportunityLineItem();
testOli.Description = 'foo';
testMap.put(testOli, 'bar');
System.assert(testMap.containsKey(testOli));
string mapValue = testMap.get(testOli);
System.assertEquals('bar', mapValue);
// After this the OLI will no longer be a key in the map.
testOli.OpportunityId = '0064000000RB2eJ';
System.assert(testMap.containsKey(testOli), 'Expected to still contain OLI');
string mapValue2 = testMap.get(testOli);
System.assertEquals('bar', mapValue2, 'OLI instance still expected to map to string bar');
This fails for me with:
System.AssertException: Assertion Failed: Expected to still contain OLI
Is this the expected behaviour?