Summarize Opportunity amounts
COUNT() counts rows and must sit alone in its SELECT.
Your task
Summarize three tagged Opportunities, including one with a null Amount.
String tag = 'AS-Q310-' + UserInfo.getUserId() + '-' +
String.valueOf(Datetime.now().getTime());
String stageName = Opportunity.StageName.getDescribe().getPicklistValues()[0].getValue();
Account parent = new Account(Name = tag);
insert parent;
List<Opportunity> seeded = new List<Opportunity>{
new Opportunity(Name = tag + '-100', AccountId = parent.Id, StageName = stageName,
CloseDate = Date.today(), Amount = 100),
new Opportunity(Name = tag + '-300', AccountId = parent.Id, StageName = stageName,
CloseDate = Date.today(), Amount = 300),
new Opportunity(Name = tag + '-Null', AccountId = parent.Id, StageName = stageName,
CloseDate = Date.today(), Amount = null)
};
insert seeded;Requirements
SELECT COUNT() FROM Opportunityshould be present- Row count should be computed from the query
- COUNT(Amount), SUM(Amount) and AVG(Amount) should be present
Aggregate rows:should be3Aggregate nonnull:should be2Aggregate sum:should betrueAggregate average:should betrue