How to Aggregate using Database.query()?
We can use Database.query() method to get Aggregate query result. We can use alias as well if we need.
//without alias
List<AggregateResult> aggResult - Database.query( 'SELECT Count (Id) FROM Account');
System.debug(aggResult[0].get ('expre'));
//with alias
List<AggregateResult> aggResult = Database.query ('SELECT Accountld accId, Count (Id) contactCount FROM Contact GROUP RY ACCOUNT’)
System.debug(aggResult[0].get ('accId') + ' ' + aggResult [0].get ('contactCount'));
Follow Us