You need to sign in to do that
Don't have an account?

Updating a Map inside a For Loop?
Hi,
I wanted to know if it is bad practice to update a map inside a for loop. When I say update I do not mean a DML update--as I know better! :) I mean can I do a get on a map and a put on that same map inside a loop. I want to read thorugh records in my loop and if I find a matching key in my map over and over, I want to keep updating the map with the latest records data? Once out of the loop then I figure I should be able to do my DML on the map.
I wanted to know if it is bad practice to update a map inside a for loop. When I say update I do not mean a DML update--as I know better! :) I mean can I do a get on a map and a put on that same map inside a loop. I want to read thorugh records in my loop and if I find a matching key in my map over and over, I want to keep updating the map with the latest records data? Once out of the loop then I figure I should be able to do my DML on the map.
Yes its actually very benificial to use maps, and very important thing to populate map
Here is the post populating maps in loops and updating them also, hope this will help you
http://abhithetechknight.blogspot.in/2013/10/logic-for-maps-having-list-at-values.html
Regards,
Abhi Tripathi
Salesforce Certified Developer