You need to sign in to do that
Don't have an account?

Display page bock table on opportunity
Plz help me , I have no idea about aggregate results.
display last two weeks opportunities sum(amount) group by stagename="closed won" and stagename ="closed lost"
week wise closed wons closed losts
1st week 2000/- 100/- ( total opportunities in 1st week )
2nd week 2500/- 250/- (total opportunities in 2st week)
please post controller
Hi,
You can use the following code,
Date lastToLastWeek=Date.today().addDays(-14);
Date lastWeek=Date.today().addDays(-7);
//query for the last two week
AggergateResult [] aggr=[SELECT SUM(Amount) amount,StageName name
FROM Opportunity
GROUP BY StageName
WHERE CreateDate>:lastToLastWeek AND CreateDate<:lastWeek];
for(AggregateResult agr:aggr)
{
String stageName=(String)agr.get('name');
if(stageName=='closed wons')
{
//get amount for closed wons using agr.get('amount')
}
else if(stageName=='closedlosts')
{
//get amount for closed losts using agr.get('amount')
}
}
Use another query to get result for this week.
Please mark as solution if this solves your problem
Thanks