You need to sign in to do that
Don't have an account?
nr123
AggregateResults doesnt recognize Owner Name Field
I need to display a summary of Opportunities by Opportunity Owner in a Visualforce Page Dashboard component. So far I can get it to group by OwnerId, but it doesnt work for Owner.Name. I get the following error: "System.SObjectException: Invalid field Owner.Name for AggregateResult".
public class QuotesRecvd{ Public String quotecount {get; set;} Public String OName {get;set;} public QuotesRecvd(string n ,string q){ this.oName = n; this.quotecount = q; } } public List<QuotesRecvd> QuotesRecvdList = new List<QuotesRecvd>(); public List<QuotesRecvd> getQuotesRecvdCount(){ AggregateResult[] agr = [SELECT Owner.Name, count(Name)FROM Opportunity WHERE Quote_Requested__c = :date.today()-1 Group By rollup (Owner.Name)]; for(AggregateResult qrcvd : agr){ QuotesRecvdList.add(new QuotesRecvd(String.valueof(qrcvd.get('Owner.Name')),String.valueof(qrcvd.get('expr0')))); } return QuotesRecvdList; }
Any suggestions? I also need to know how to create a test for this.
Any help would be greatly appreciated!
Change this
to
This will give you owner name
The reason for this is that whenever you use native Name field of any object for group by aggr query return Name field. Like in above example you used Owner.Name that is Name field of User object so it return Name field in aggr result.
All Answers
Change this
to
This will give you owner name
The reason for this is that whenever you use native Name field of any object for group by aggr query return Name field. Like in above example you used Owner.Name that is Name field of User object so it return Name field in aggr result.
That fixed it! Thank you.
Your Welcome :)
hi Shashikant
Our of query is select name,Qwner.Name from account
then i think your soltion
qrcvd.get('Name')
will not work