+ Start a Discussion
Hemalatha  ParuchuriHemalatha Paruchuri 

How to display AggregateResult Of 2 fields in custom object


I have a custom object My__order__c and lookup to Account(Customer__c). In my order object have a field like Transaction ID.
In my order object have so many orders that means one account have multiple orders ..based on that they have Transaction ID and one more field is like net total__c.
my question is i have to display customer name,Transion id,net total but in that customer name i got customer id..so how can i get custome name(Account name).

Visualforce page:

<apex:page standardController="my_order__c" sidebar="false" extensions="Totalorders">
 <apex:form >
 <apex:pageBlock >
 <apex:pageBlockTable value="{!results}" var="r">
  <apex:column value="{!r['Customer__c']}">

  <apex:facet name="header">CustomerID</apex:facet>


   <apex:column value="{!r['Transaction_ID__c']}" >
<apex:facet name="header">Transaction ID</apex:facet>
     <apex:column value="{!r['Total']}">
      <apex:facet name="header">Net Total </apex:facet>

Extension :

public with sharing class Totalorders {

  public Totalorders(ApexPages.StandardController controller) {
     public AggregateResult[] results {
        get {
            return [select Transaction_ID__c,Customer__c,Sum(Net_Total__c)Total From my_order__c GROUP BY Rollup(Transaction_ID__c,Customer__c)];

SandhyaSandhya (Salesforce Developers) 
Hi Hemalatha Paruchuri,

In your visual force page you need to use
Customer__r.Name instead of Customer__c
Hope this helps you!

If this solves your questions please mark it as solved.

Thanks and Regards