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
Denis O'LearyDenis O'Leary 

Map is losing it's value pair after upsert

Hi,

I have a map which consists of an sObject and a custom class, i'm mapping objects that i need to process to a class.
map<service_call__c, JobResponse> scTaskList = new map<service_call__c, JobResponse>();
My issue is I perform an upsert on the Service call object before I send this scTaskList map into another method for some further processing. After I perform that upsert the Service_call__c object that is in the map will get an ID assigned to it (if it wasn't an exisiting record) but it then looses it's mapped Job response. 

Is there anything I can do to prevent this? 
Best Answer chosen by Denis O'Leary
Denis O'LearyDenis O'Leary
Hi RD,
I reveresed the order in the Map from map<service_call__c, JobResponse> to map<JobResponse, service_call__c>. The issue it seems was to do with service_call__c changing after the Upsert (by it getting assigned an ID) that it now was a different Key in the map and therefore loosing it's value. 

All Answers

RD@SFRD@SF
Hi Denis,

Can you share the code around the upsert you are doing, would be helpful.

RD
Denis O'LearyDenis O'Leary
Hi RD,
I reveresed the order in the Map from map<service_call__c, JobResponse> to map<JobResponse, service_call__c>. The issue it seems was to do with service_call__c changing after the Upsert (by it getting assigned an ID) that it now was a different Key in the map and therefore loosing it's value. 
This was selected as the best answer