You need to sign in to do that
Don't have an account?

Two Aggregate Results in one list
Hi,
I've tried to add two aggregate results in one list, but I don't know if its correct because I don't know how can I show the results at the visualforce page.
Just for testing....
What is my plan, I want to count the number of accounts grouped by account Id, this make no sense but for the test its ok and on the other hand I want to count the number of sales and the sum of the sales grouped by account Id. The both aggregate results should be maped into one list.
Could you tell me is my code correct and how can I display the results?
Sascha
I've tried to add two aggregate results in one list, but I don't know if its correct because I don't know how can I show the results at the visualforce page.
Just for testing....
What is my plan, I want to count the number of accounts grouped by account Id, this make no sense but for the test its ok and on the other hand I want to count the number of sales and the sum of the sales grouped by account Id. The both aggregate results should be maped into one list.
Could you tell me is my code correct and how can I display the results?
Public Class VTP32_class { public String CombinedSummary { get; set; } Public VTP32_class() { } Public class CombinedSummary { public Integer CountAcc {get; set;} public Id UId {get; set;} public Integer CountSales {get; set;} public Double Brutto_BWS {get; set;} Public CombinedSummary (AggregateResult arM, AggregateResult arS) { CountAcc = (Integer) arM.get('CountAcc'); UID = (Id) arS.get('Id'); CountSales = (Integer) arS.get('CountSales'); Brutto_BWS = (Double) arS.get('Brutto_BWS'); } } Public List<CombinedSummary> generateWrappers() { Map<Id, AggregateResult> AccMap = new Map<Id, AggregateResult>(); Map<Id, AggregateResult> AccSales = new Map <Id, AggregateResult>(); List<CombinedSummary> combinedSummaries = new List<CombinedSummary>(); FOR(AggregateResult arM: [SELECT COUNT(OwnerId) CountAcc, Id FROM Account GROUP BY Id]) { AccMap.put((Id)arM.get('Id'), arM); } FOR(AggregateResult arS: [SELECT COUNT(Id) CountSales, SUM(BWS_Brutto__c) Brutto_BWS, Einzelrisiko__r.Gruppenvertrag__r.Unternehmen__r.Id FROM Umsatz__c GROUP BY Einzelrisiko__r.Gruppenvertrag__r.Unternehmen__r.Id]) { AccSales.put((Id)arS.get('Einzelrisiko__r.Gruppenvertrag__r.Unternehmen__r.Id'), arS); } Set<Id> AccSet = new Set<Id>(); AccSet = AccSales.keySet(); AccSet.addAll(AccSales.keySet()); FOR (Id Id : AccSet) { combinedSummaries.add(new CombinedSummary(AccMap.get(Id), AccSales.get(Id))); } Return combinedSummaries; } }Thanks,
Sascha
I think the best approach is to use a Map instead of using a List. For example, using a Map you could get a value using this code below (just an example ok?):
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Regards.
If I tried to display I get the following error:
Error: Expression of type Text cannot be subscripted.
Since you defined generateWrappers as a Map, you don't need an interation. So, your code shoud be:
Could you send the entire code? I'll try to fix it.
Check out this code bellow (an example ok?):
It's working fine to me.
Regards.
below you will find the test code. If I try to save the page I get the error:
Unknown property 'test_class.mapTest'