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
Bryn JonesBryn Jones 

Total Value of Opportunites in VF page

I would like to display the total value of all opportunities closed this month in a visual force page. I am having troubling figuring out how to write the code for this...

Bryn
Phillip SouthernPhillip Southern
Hi Bryn, so not sure what you have so far...but one option is in your controller or extension that the visualforce page is referencing...to do an aggregate query of all opportunitites, and just don't do a group by...but still do some filtering.

sample:
Date filterDate = date.newinstance(system.now().year(), system.now().month(),1);
AggregateResult ar = [select sum(amount) total from opportunity where closedate >= :filterdate and isclosed=true];
system.debug(ar.get('total'));

Bryn JonesBryn Jones
Sorry should have made my self clear...

I have built a company dashboard and i would like to get the total value of closed opportunites this month on there. Right now the controller is Account as we enter our sales in an account specially built for our KPI's and i have built sales and target dials from those numbers....

how do you do aggregate query of all opportunitoesa cross the whole SF.com site for all accounts.

I really want to sort of duplicate the SalesLeaderboard by InsightSquared from the appexchange....this will help you understand what i mean....


Thanks for the quick responce...
Bryn
Phillip SouthernPhillip Southern
Thats ok but to be honest I'm still not following....you have a dashboard and you want the total on there...which could mean you can edit the reports behind the dashboards to include all opportunities.....but how does a visualforce page play into this?
Bryn JonesBryn Jones
Sorry for the confusion...i have built a custom dashboard in a VF page....:) sorry i should have said that earlier.....

Bryn