You need to sign in to do that
Don't have an account?
KR_Force
How to loop through the map values... Compile Error: Loop must iterate over a collection type: SOBJECT:Asset
I'm actually trying to get the assets from the map based on account ID and loop through the values to get the Product_Family__c.
Map<ID,Asset>actAstMap=new Map<ID,Asset>();
for (Asset a1: actAstMap.get(ActID)){
if(a1.Product_Family__c!=null ||a1.Product_Family__c<>''){
pFamily.add(a1.Product_Family__c);
}
}
Any help will be much apprecitated.
Map<ID,Asset>actAstMap=new Map<ID,Asset>();
for (Asset a1: actAstMap.get(ActID)){
if(a1.Product_Family__c!=null ||a1.Product_Family__c<>''){
pFamily.add(a1.Product_Family__c);
}
}
Any help will be much apprecitated.
Glad that it helped.
Now the new issue is becuase of your improper usage of lActAgentcontMap
you have declared it as Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
which means that both the key and value are of type ID but in you 69 th line you have passed as follows
lActAgentcontMap.get(lactID)
where lactID is a sObject of type Linked_Account__c
so you have to replace that 69 th line as follows
for(Linked_Account__c lactID:actLActMap.get(c.AccountID)){aContID.add(lActAgentcontMap.get(lactID.Id));} // I have replaced lactId to lact.Id
Cheers..!!
All Answers
First thing you need to understand is that the for loop can iterate only using collections like LIST, SET... In the above code you have used actAstMap.get(ActID)
which will return single Asset (which is not a collection).
To fix this you need to change the Map as follows
Map<ID,List<Asset>>actAstMap=new Map<ID,List<Asset>>(); // Replace the first line with this line
so now it retuns List of assets for the Account Id.
Hope This Helps...!!
Cheers
You can loop through a map using keyset function:
eg
keySet():
Returns a set that contains all of the keys in the map.
Thanks,
Vishal
Here is my code
Glad that it helped.
Now the new issue is becuase of your improper usage of lActAgentcontMap
you have declared it as Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
which means that both the key and value are of type ID but in you 69 th line you have passed as follows
lActAgentcontMap.get(lactID)
where lactID is a sObject of type Linked_Account__c
so you have to replace that 69 th line as follows
for(Linked_Account__c lactID:actLActMap.get(c.AccountID)){aContID.add(lActAgentcontMap.get(lactID.Id));} // I have replaced lactId to lact.Id
Cheers..!!