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.

}
  • What exactly are you trying to achieve? – RCS Jan 19 '17 at 9:48
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);
}
  • 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 Jan 19 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.