0

I am working towards getting my controller to pass queries into a visualforce gauge component. The first part works in that I can make a query convert to an integer and display on the chart. I want to make a query to set the maximum value for the gauge.

I have this code but I get an error invalid type on the List max line. What am I doing wrong it looks exactly like the first part...

public with sharing class ISOGaugeController2b {

public List<gaugeData> getData() {
//          Integer actual = 0;
//          Integer TotalAmount = 0;
//          Integer thisMonth = date.Today().month();

        AggregateResult Actuals = [select sum(amount__c) sum 
                                FROM Actuals__c 
                                Where amount__c != null 
                                AND ISO_Goal__r.OwnerId = :UserInfo.getUserId()];

        List<gaugeData> data = new List<gaugeData>();
        data.add(new gaugeData('Actual', Integer.valueof(actuals.get('sum'))));
        return data;
    }
// Wrapper class
public class gaugeData {

    public String name { get; set; }
    public Integer size { get; set; }

    public gaugeData(String name, Integer data) {
        this.name = name;
        this.size = data;
    }
}        

public List<maxData> getMax(){

        Double maximum = [select Goal__c 
                        FROM ISO_Goal__c 
                        Where Goal__c != null 
                        AND OwnerId = :UserInfo.getUserId()];

    List<maxData> max = new List<maxData>();
    max.add(new maxData('Maximum', Integer.valueof(maximum.get(Goal__c))));
    return max;
}
}
  • maxData Wrapper class ? Double maximum instead AggregateResult will be return type – Ratan Paul May 5 '16 at 2:43
  • 1
    Hi, you have a SOQL query on ISO_Goal__c object which will return a list of ISO_Goal__c object but you have assigned it to a variable of type Double. As Ratan suggested, the query must be a aggregate query instead of a normal SOQL query. – ajinkyah May 5 '16 at 6:10
  • Are you sure AggregateResult is the correct query type? I am not doing a sum or avg I just want to return the one record that should match the query and display the currency field goal__c. – Dan Wooding May 5 '16 at 13:46
  • Where is your maxData wrapper class? Also, the query(Double maximum = [select Goal__c....) will return you List<ISO_Goal__c> and not a Double – Novarg May 6 '16 at 7:21
1

Your comment states:

I just want to return the one record that should match the query and display the currency field goal__c

Your method:

public List<maxData> getMax(){

    Double maximum = [select Goal__c 
                    FROM ISO_Goal__c 
                    Where Goal__c != null 
                    AND OwnerId = :UserInfo.getUserId()];

List<maxData> max = new List<maxData>();
max.add(new maxData('Maximum', Integer.valueof(maximum.get(Goal__c))));
return max;

}

should be (to return just one value) - assuming, as per your comment, that one record will always exist (otherwise, extend to include error handling)

public List<maxData> getMax(){

        return new List<maxData> {[select Goal__c 
                        FROM ISO_Goal__c 
                        Where Goal__c != null 
                        AND OwnerId = :UserInfo.getUserId()][0].iso_goal__c};
}

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.