2

Please find my below code:

public with sharing class IncForRep{

    public Summary[] Summaries { get; set; }

    public IncForRep()
    {    
        List<Incident__c> results = [SELECT 
        ID , Rep_Lookup_id__c , Rep_Lookup_id__r.Name , Name FROM Incident__c
        where Rep_Lookup_id__c <> null
        ];

        Summaries = new List<Summary>();
        for (List <Incident__c> ar : results) {
            Summaries.add(new Summary(ar));
        }
    }    

    public class Summary {
        public String ID{ get; private set; }
        public String INCNAME{ get; private set; }
        public String RepName{ get; private set; }
        public String RepId{get;private set;}

        public Summary(AggregateResult ar) {
            ID = (Integer) ar.get('ID');
            INCNAME= (String) ar.get('NAME');
            RepName = (String) ar.get('RepName'); 
            RepId = (String) ar.get('Rep_Lookup_id__c ');           
        }
    }
}

getting error:

Compile Error: Constructor not defined: [IncForRep.Summary].(LIST) at line 14 column 27

Can someone help me here?

6

I'm guessing you've adapted this code from elsewhere, as the constructor for the Summary class expects a parameter of type AggregateResult:

public Summary(AggregateResult ar) {
    ID = (Integer) ar.get('ID');
    // etc.

Aggregate results are used when you use aggregate functions in SOQL, such as SUM(). Your SOQL query doesn't contain any aggregate functions and so returns a list of Incident__c records which you're storing in the list results. Since you want to create summaries for each of these records you need to adapt your constructor accordingly (or even overload it, which means adding a second constructor that takes different parameters):

public class Summary {
        public String ID{ get; private set; }
        public String INCNAME{ get; private set; }
        public String RepName{ get; private set; }
        public String RepId{get;private set;}

        public Summary(Incident__c i) {
        ID = i.Id;
        INCNAME= i.Name;
        RepName = i.Rep_Lookup_id__r.Name;
        RepId = i.Rep_Lookup_id__c;
    }
}
4

You are getting this error since constructor of Summary expects an AggregateResult, instead of that that you are passing an list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.