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

Updating a Map inside a For Loop?


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

Abhi Tripathi
Salesforce Certified Developer