You need to sign in to do that
Don't have an account?
kreshocs
How to select an aggregate query into a map?
To take the example from the docs:
AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId];
Now try
Map<ID, AggregateResult> resultsMap = [SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId];
This won't work even though CampaignId is of type ID. To make it work, alias CampaignId with Id:
Map<ID, AggregateResult> resultsMap = [SELECT CampaignId Id, AVG(Amount) FROM Opportunity GROUP BY CampaignId];
Interestingly, the case here does matter. Aliasing with id or ID won't work.
This worked on March 28th 2012 (seriously, I swear it did! :-), but does not any more.
Please support my idea at https://sites.secure.force.com/success/ideaView?id=08730000000hmhOAAQ to reinstate this behavior.
I just tried this in Spring 12 in my Dev Org:
This works as expected. Note that aliased Id field cannot be null or you get an exception.
All Answers
If it doesn't work, just loop through the results and manually add it to a Map.
Just a regular for-loop would work; you can cast the object into an ID.
Thanks Damien, sfdcfox, but did you actualy read the message to the end?
I did read your message at the end, but it is irrelevant to the answer of your question.
I just tried this in Spring 12 in my Dev Org:
This works as expected. Note that aliased Id field cannot be null or you get an exception.
It works indeed with your extra restriction. Thanks for finding the problem.
Line: 1, Column: 1
System.ListException: Row with null Id at index: 0
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.