Currently, onclick of a button, I'm displaying a bar chart with all data available in that object for that particular filters (using Javascript Remote Action).

List<AggregateResult> ListName = 
    [SELECT SUM(Field1__c), SUM(Field2__c), 
     WHERE Name In :abcd 
     AND (createdDate>=: startdatenew AND createdDate>= :enddatenew)];

I need to have another list with a different created date criteria.

List<AggregateResult> OldListName = 
    [SELECT SUM(Field1__c), SUM(Field2__c), 
     WHERE Name In :abcd  
     AND(createdDate>=: startdateold AND createdDate>= :enddateold)];


List<ABCD> NEWLIST = new List<ABCD>();
for(AggregateResult ar : ListName ) {
    ListName .add(new ABCD(String.ValueOf(ar.get('Name'))));
return NEWLIST;

Can I return two such lists?

1 Answer 1


If you want to display chart where you will have particular date, you should define your range in Where, group it by date and in the for loop populate chartdata:

Given example selects opportunity amount for year 2014 and 2016, and groups it by month and amount

public static List<Data> getChartData() {

    List<Data> data = new List<Data>();

    List<AggregateResult> groupedResults = [
        select calendar_year(closedate) y, calendar_month(closedate) m, sum(amount)s
        from opportunity 
        where calendar_year(closedate) in (2014,2016)
        group by calendar_year(closedate), calendar_month(closedate) 
        order by calendar_year(closedate), calendar_month(closedate)

    for (AggregateResult ar :groupedResults) {
        string year = string.valueof(ar.get('y'));
        string month = string.valueof(ar.get('m'));
        double sum = (Double)ar.get('s');

        data.add(new Data(year + '/' + month, sum));

    return data;


enter image description here

  • Thank you for the answer . But my requirement is to display two lists in one chart . e.g I want to display records of current year and last year. So I do I need to create two methods for that?
    – SFDCRookie
    May 13, 2016 at 7:36
  • @sfdcrookie, please find a moment to check updated answer May 13, 2016 at 16:56

You must log in to answer this question.

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