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
sagar077sagar077 

Hello, Please me on this requirement. Count Account with Diffrenent Industry(e,g. For Industry Electronics we have 3 Accounts) using Map

Hello, Please me on this requirement.

Count Account with Different Industry(on account picklist fields is there)(e,g. For Industry Electronics we have 3 Accounts) using Map.

plz help me i am new in apex collection.
ShirishaShirisha (Salesforce Developers) 
Hi Sagar,

Greetings!

Here is the document which will give the sample code for counting the contacts with the same parent Account.

https://developer.salesforce.com/forums/?id=906F0000000AcdaIAC

You can make changes in the code as per your code.

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Andrew GAndrew G
Why not just create a grouped report based on industry with a count and hiding the detail lines?

Think about the business need.   If i'm looking at the detail of an Account, do I really need to, at that time, know that there are x number of other accounts in the same industry?   A report will give the information you need.

Regards
Andrew
 
ayu sharma devayu sharma dev
Hello Sagar
Please try the below code.
 
List<AggregateResult> agResults = [ SELECT Count(Id) cnt, Industry__c ind FROM Account Group By Industry__c ]; 
Map<String, Decimal> mapIndustryToAccCount = new Map<String, Decimal>();
for( AggregateResult ag : agResults ){
    mapIndustryToAccCount.put( (String)ag.get('ind'), (Decimal)ag.get('cnt') );
}
System.debug( mapIndustryToAccCount );

Let me know if it works.

Regards
Ayush Sharma