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
jyovasjyovas 

help with SOQL aggregate funtions

I have two objects Portfolio__c with a formula filed  Index__r.Chg_Pct__c and a child object position(s) with a field

Daily_Perf__c

 

I want the SUM(Daily_Perf__c ) from positions while selecting each portfolio object

 

when I executed the following query


select  Index__r.Chg_Pct__c  , (select SUM(Daily_Perf__c) from positions__r)  from Portfolio__c

 

I get the error "Only root querires support aggregate expressions"

 

If  I go from child and use Group BY

 

 

select SUM(Daily_Perf__c) dailypref, Portfolio__r.Index__r.Chg_Pct__c  from position__c
group by  Portfolio__r.Index__r.Chg_Pct__c

 

I get the error "field Chg_Pct__c cannot be grouped in a query call . Is it becuase its a formulat filed ?

 

How do I  do SOQL simillar to Rollup summary Filed in salesforce ?

 

Thanks,

-John

Ankit AroraAnkit Arora

You can not use aggregate query as inquery because it returns List<AggregateResults> and SOQL query returns List<SObject> or map<Id, SObject>.

 

Also you can only group the fields those have "groupable=true" in query call. You need to fetch the aggregate result first and then use the result in your query.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Scott.MScott.M

Is there any way to make a field groupable and is there any documentation on what can and can't be groupable? 

 

Thanks! :)

 

Scott