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
RobJCowellRobJCowell 

SOQLBuilder aggregate functions

So another SOQLbuilder question - why is SUM(Total_USD_Gross__c) the only field in the output SQL ?

 

companyquery = new SoqlBuilder()
                .selectx('Event_to_Deal__r.Client_Company__r.ID')
                .selectx('Event_to_Deal__r.Client_Company__r.Name')
                .selectsumx('Total_USD_Net__c')
                .selectsumx('Total_USD_Gross__c')
                .fromx('Event_Costs__c')
                .wherex(new SetCondition('Event_to_Deal__r.Client_Company__r.ID').inx(comps))
                .groupByx('Event_to_Deal__r.Client_Company__r.ID')
                .toSOQL();

  which yields the following SOQL

 

SELECT SUM(Total_USD_Gross__c) FROM Event_Costs__c WHERE Event_to_Deal__r.Client_Company__r.ID IN ('a0220000004aPRAAA2','a0220000006Fb7CAAS','a0220000004ZaYxAAK') GROUP BY Event_to_Deal__r.Client_Company__r.ID

 

Where are ID, Name and the other SUM ?  The following manual SOQL works, and is the kind of thing I'm expecting SOQLbuilder to construct

 

SELECT Event_to_Deal__r.Client_Company__r.ID,Event_to_Deal__r.Client_Company__r.Name,SUM(Total_USD_Gross__c) Gross, SUM(total_USD_Net__c) Net FROM Event_Costs__c WHERE Event_to_Deal__r.Client_Company__r.ID IN ('a0220000004aPRAAA2','a0220000006Fb7CAAS','a0220000004ZaYxAAK') GROUP BY Event_to_Deal__r.Client_Company__r.ID,Event_to_Deal__r.Client_Company__r.Name

 

Best Answer chosen by Admin (Salesforce Developers) 
Richard Vanhook (Salesforce)Richard Vanhook (Salesforce)

This is currently a limitation and needs to be addressed.

All Answers

Richard Vanhook (Salesforce)Richard Vanhook (Salesforce)

This is currently a limitation and needs to be addressed.

This was selected as the best answer
RobJCowellRobJCowell

It's strangely comforting to know it's not my poor usage then ;-)

 

I'll work around it for now, but I'm hoping to contribute a fix back to the community when I'm not under deadlines