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
Abhi MehtaAbhi Mehta 

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 ?

Harsh P.Harsh P.
Use the below link .
Hope it will reach you at the destination:

https://developer.salesforce.com/forums/?id=9060G0000005pBpQAI

Thanks & regards,
Harsh P.
Piyush Gautam 6Piyush Gautam 6
Hi,

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;