function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ledap13ledap13 

Custom Object linking to account

Hi ..
I have a master-detail relationship to my object Order__c and account.
When I ausführe my query:
List <AggregateResult> result = [SELECT Account__c, COUNT (name), SUM (Price__c) total FROM Order__c GROUP BY Account__c];

How do I get through the Account__c field returns the name of the account?
Gonzalo AbrunaGonzalo Abruna
You need go to the Account relationship, something like this:

List <AggregateResult> result = [SELECT Account__c, Account__r.Name, COUNT (name), SUM (Price__c) total FROM Order__c GROUP BY Account__c];


To get the value, it would be enough to do something like:
String accountName = record.Account__r.Name;

Regards,

G
ledap13ledap13
Unfortunately, the script does not work.
I get the following error:
Error: Compile Error: Field must be grouped or aggregated: Name at line 26 column 40

Can you help me?