+ Start a Discussion
priya burghatepriya burghate 

While creating custom chart showing 'Invalid field Owner.name for AggregateResult' error has occured

I want to create pie chart account for owner having there accounts but it shows Invalid field 'Owner.name' error in aggregateResult..
Can anyone plz help to sort out?
public with sharing class Graph1 
{
    
 public List<PieWedgeData> getPieData1() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<AggregateResult> groupedResults = [SELECT Owner.name, count(name)cnt
                                              FROM Account
                                              GROUP BY Owner.name];
        for (AggregateResult ar : groupedResults)  {
            data.add(new PieWedgeData(String.valueOf(ar.get('Owner.name')),Integer.valueOf(ar.get('cnt'))));
        
    }
    return data;
    }

    // Wrapper class
    public class PieWedgeData {

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

        public PieWedgeData(String name, Integer data) {
            this.name = name;
            this.cnt = cnt;
        }
        }
   }
Best Answer chosen by priya burghate
Jagan ReddyJagan Reddy
data.add(new PieWedgeData(String.valueOf(ar.get('Owner.name')),Integer.valueOf(ar.get('cnt'))));

in the place of owner.name give name

data.add(new PieWedgeData(String.valueOf(ar.get('name')),Integer.valueOf(ar.get('cnt'))));

try it

All Answers

Jagan ReddyJagan Reddy
data.add(new PieWedgeData(String.valueOf(ar.get('Owner.name')),Integer.valueOf(ar.get('cnt'))));

in the place of owner.name give name

data.add(new PieWedgeData(String.valueOf(ar.get('name')),Integer.valueOf(ar.get('cnt'))));

try it
This was selected as the best answer
priya burghatepriya burghate
thank you so much Jagan Reddy...
It works out....
thank you so much...:-)
Jagan ReddyJagan Reddy
Welcome :)