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
SharndeepkaurSharndeepkaur 

iterate map of Id and list of sobject

Eg I have  Map1:  Map<Id,List<FeedComment>>
So i am creating Map of FeedItem and its related FeedComments

Now after filling this map i want to access FeedComment field (eg createdbyid) and place this Field Id in Set and use it.How can do that without iterating 'Map1' 2 times in for loop?
Suraj Tripathi 47Suraj Tripathi 47
Hi Sharndeepkaur,
You can try this one ,

Set<Id>fieldCreatedByIdSet= new Set<Id>();
for(Id i:Map1.Keyset()){
for(FeedComment feed :Map1.get(i)){
fieldCreatedByIdSet.add(feed.CreatedById);
}
}

Pls Mark it as Best answer If You find it helpful !!
Thanks
SharndeepkaurSharndeepkaur
Hi @Suraj Tripathi 47,
Thank you for the response.
Yes,i can get value like this but here we have to first iterate Keyset and then again use inner for loop for getting values.Is there another way to do this without using 2 for loops?
I have read in Sf docs that we have to avoid using double for loops and use Map instead or something else.Can you please  assist regarding this?