I have map<AccountId, list<case>> and the list of case contains case sub issue field which is a picklist. Now I want to show the count of each sub issue related to the account on field(number) on account. How to iterate a map for this ?
List<Account> accList= new List<Account>(); map<id, Account> accCaseMap= new Map<id, Account>([SELECT Id , NumberFieldApiName_c, (select id from Cases) from Account]);
Hope it will reach you at the destination:
https://developer.salesforce.com/forums/?id=9060G0000005pBpQAI
Thanks & regards,
Harsh P.
Please try the below code as per your scenario.
If helpful please mark as solved.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
List<Account> accList= new List<Account>();
map<id, Account> accCaseMap= new Map<id, Account>([SELECT Id , NumberFieldApiName_c, (select id from Cases) from Account]);
for(Id accId: acccaseMap.keyset()){
list<case> caseList=acccaseMap.get(accId).Cases;
integer caseSize= caseList.size();
Account acc= new Account (Id= accId, NumberFieldApiName_c= caseSize);
acclist.add(acc);
}
update accList;