You need to sign in to do that
Don't have an account?
PC
The values of Map id getting null after I perform Insert operation on the key set.
I am trying to insert the a Map of <Case,List<Case> as parents and their related child cases using apex. But once I insert the Map key set , the map values get null.
Why the values are geting set to null?
Map<Case,List<Case>> parentChildMap = new Map<Case,List<Case>>(); List<Case> parentCases = new List<Case>(); for(CaseWrapper wrap: caseWrapperList){ parentChildMap.put(wrap.parentCase,wrap.childCases); } System.debug('map before insert==>'+parentChildMap); if(parentChildMap.keySet() !=null){ parentCases.addAll(parentChildMap.keySet()); insert parentCases ; System.debug('map after insert==>'+parentChildMap); } Debugs: map before insert==> {Case:{Subject=1}=(Case:{Subject=1.1}), Case:{Subject=2}=(Case:{Subject=2.2})} map after insert==> {Case:{Subject=1, Id=5000K00002cxQsWQAU}=null, Case:{Subject=2, Id=5000K00002cxQsXQAU}=null}
Why the values are geting set to null?
Please check this link to see if it helps
https://salesforce.stackexchange.com/questions/296368/sobject-key-of-map-mutated-returns-null-but-serializing-returns-the-value
Thanks for the link. Yes if I debug Json.serialize(parentChildMap) then I am getting the map values as well. But can you help me with how can i use this serialized data to loop over something like:
I think the following might be the solution to your problem,
I mean can you concatenate some field values in the inserted data into a unique value before and after the data is inserted