0

I have below List where OwnerId field value may be the map key. I need to find out the Id from the List element for which the map key matches the OwnerId.

List

List<Account_List_vod__c> ExistActList = [select Id, Icon_Name_vod__c, Name, OwnerId from Account_List_vod__c where OwnerId in :MapOfTierObj.keySet()];

MapKey

for (Id key : MapOfTierObj.keySet()) 
 {

.....Some code.......
.........Check if Key matches with an element in ExistActlist, then bring the Id value of corresponding element.

}
1
  • What exactly are you trying to achieve?
    – RCS
    Commented Jan 19, 2017 at 9:48

1 Answer 1

1

Try Below code: Using below code you'll get all the Account_List_vod__c Id's associated to a particular OwnerId in tempMap that can be used for further processing

//Create a Map with Owner Id as Key and value as Set of Account_List_vod__c
Map<Id, Set<Id>> tempMap = new Map<Id, Set<Id>>();
for(Account_List_vod__c obj: [select Id, Icon_Name_vod__c, Name, OwnerId from Account_List_vod__c where OwnerId in :MapOfTierObj.keySet()]) {
    if(!tempMap.containKey(obj.OwnerId))
       tempMap.put(obj.OwnerId, new Set<Id>{obj.Id}); 
    else
       tempMap.get(obj.OwnerId).add(obj.Id);
}
1
  • But incase if the Account_List_vod__c has same OwnerId then how are you going to do that? Any which ways you can convert the Map value of Set to Id totally depends on the logic
    – RCS
    Commented Jan 19, 2017 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .