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
Urvish ShahUrvish Shah 

Map<Opportunuty,List<OpportunityLine>>. Insert Opportunity and related OpportunityLines

From the lightning component I am constructing a List<Object> like below for opportunity and opportunityLine data.

var oppList = [ 
   { 
      "csd":"testcds",
      "msd":"testmsd",
      "products":[ 
         { 
            "id":"123",
            "qty":"5"
         },
         { 
            "id":"456",
            "qty":"3"
         }
      ]
   },
   { 
      "csd":"testcds1",
      "msd":"testmsd1",
      "products":[ 
         { 
            "id":"1231",
            "qty":"51"
         },
         { 
            "id":"4561",
            "qty":"31"
         }
      ]
   }
];

Each of the oppList is basically an Opportunity and products under that item is data for opportunityline. Now I am deserialiing this as a Map<Opportunity,List<OpportunityLines>>

To be able to insert OpportunityLines I have to get OpportunityId. For that I have to insert the key of the map first and then use those id to insert related opportunitylines. 

As, object as a key changes after an insert operation as it adds ID field and thus returns null for the key with which we build the map. Any idea how do I get this to work without inserting opportunities in for loop?