Salesforce documentation suggests that aggregrate soql results must first be assigned to an instance of the AggregateResult class, as shown below:
AggregateResult groupedResults = [SELECT AVG(Amount)aver FROM Opportunity]; Object avgAmount = groupedResults.get('aver');
I'm wondering, is it possible for a more elegant solution that assigns the aggregated field directly to a variable of the same type? EG:
mainAccount.Active_Total_Opps_Rollup__c = [SELECT SUM(Amount) FROM Opportunity WHERE AccountID IN :ID_Group];
Obviously what I've written gives an error, because the query returns a list of results and not a single value. But is there a way for me to compactly indicate that I want to return only the aggregated value?