0

I've changed the code again, but I still get an error.

But now I get the error: Constructor not defined: [VTP31_class.CombinedSummary].(AggregateResult, AggregateResult) in row 35, column 35

CLASS

    Public Class VTP31_class {

    Public VTP31_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 List<CombinedSummary> generateWrappers() {
        Map<Id, AggregateResult> AccMap = new Map<Id, AggregateResult>();
        Map<Id, AggregateResult> AccSales = new Map <Id, AggregateResult>();
        //Set<Id> AccSet;
        List<CombinedSummary> combinedSummaries = new List<CombinedSummary>();

        FOR(AggregateResult ar: [SELECT COUNT(OwnerId) CountAcc, Id FROM Account GROUP BY Id]) {
            AccMap.put((Id)ar.get('Id'), ar);
        }

        FOR(AggregateResult ar: [SELECT COUNT(Id) CountSales, SUM(BWS_Brutto__c) Brutto_BWS, Parent2__r.Parent1__r.Account.Id FROM Sales__c GROUP BY Parent2__r.Parent1__r.Account.Id]) {
            AccSales.put((Id)ar.get('Id'), ar);
        }

        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;

}

PAGE

still open

EDIT 27.11.2018

I've added the following code as constructor, but it still not works.

public CombinedSummary (AggregateResult ar) {
    CountAcc = (Integer) ar.get('CountAcc');
    UID = (Id) ar.get('Id');
    CountSales = (Integer) ar.get('CountSales');
    Brutto_BWS = (Double) ar.get('Brutto_BWS');
    }

EDIT 04.01.2019

CLASS shows no more errors:

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;

}

}

PAGE, the output does not work, I get the error "Unknown property 'VTP32_class.generateWrappers'"

<apex:page controller="VTP32_class" sidebar="false">   

<apex:repeat value="{!generateWrappers}" var="var">
    {!var['AccSales'].CountSales}
</apex:repeat>

</apex:page>
1
  • 1
    Can you expand a bit on what you need? Oct 29, 2018 at 19:34

1 Answer 1

2

You can extend the wrapper class pattern you are already using with the Summary1 and Summary2 objects. Call a new object CombinedSummary, for example:

public class CombinedSummary {
    public Integer Anz {get; set;}
    public Double Amount_BWS {get; set;}      
    public Integer Anz{get; set;}
    public Double BWS {get; set;}    
    public Double JZ {get; set;}      
    public Id OwnerId {get; set;}
}

Include in that wrapper class the combined set of fields from the two aggregate queries, as above, but only one field for the owner.

Then you'll need to construct some Maps keyed on the shared value between these two queries - the OwnerId / Sales_Rep__c. Something like this, for example:

List<CombinedSummary> generateWrappers() {
    Map<Id, AggregateResult> oppMap = new Map<Id, AggregateResult>();
    Map<Id, AggregateResult> salesMap = new Map<Id, AggregateResult>();
    Set<Id> ownerSet;
    List<CombinedSummary> combinedSummaries = new List<CombinedSummary>();

    for (AggregateResult ar : [SELECT COUNT(Id) Anz, SUM(Amount_BWS__c) Amount_BWS, SalesRep__c FROM Sales__c GROUP BY SalesRep__c]) {
        salesMap.put(ar.get('SalesRep__c'), ar);
    }

    for (AggregateResult ar : [SELECT COUNT(Id) Anz, SUM(Amount) BWS, SUM(JZ__c) JZ, Account.OwnerId FROM Opportunity GROUP BY Account.OwnerId]) {
        oppMap.put((Id)ar.get('OwnerId'), ar);
    }

    ownerSet = new Set(salesMap.keySet());
    ownerSet.addAll(oppMap.keySet());

    for (Id ownerId : ownerSet) {
        combinedSummaries.add(
            new CombinedSummary(
                salesMap.get(ownerId),
                oppMap.get(ownerId)
            )
        );
    }

    return combinedSummaries;
}

This is a little rough but I think you can see the outline of the solution. You'd need then to implement a constructor for CombinedSummary that accepted one of each type of AggregateResult and populated its fields accordingly, taking care to handle null parameters safely.

The signature of your constructor should be

public CombinedSummary(AggregateResult salesAR, AggregateResult oppAR) {
12
  • Thanks David, I've changed the code but now I get an error. Could you help me again.
    – peXeq
    Oct 30, 2018 at 9:25
  • 2
    You have to cast the result of ar.get() to an Id. Apologies, I forgot that in my code.
    – David Reed
    Oct 30, 2018 at 11:57
  • Thanks David, I think we are close to the end, but now get an error. Could you please help me again.
    – peXeq
    Oct 30, 2018 at 14:06
  • The error you're getting really means just what it says. You must actually write the constructor for the CombinedSummary class, as I mentioned above. It can follow a similar pattern to what you already created in your other wrapper classes.
    – David Reed
    Oct 30, 2018 at 14:09
  • 1
    Just so you know, it's helpful to preserve the original context (your first question) so that future readers will understand the answers. You can definitely open further questions if you have detailed follow-ups (beyond a quick comment).
    – David Reed
    Oct 30, 2018 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .