Skip to content
Michael Kolodner edited this page Dec 2, 2022 · 28 revisions

This repository demonstrates creating an object (DashboardTarget) for storing target numbers for dashboard Dynamic Gauge components. Without something like this if you want to use dynamic gauges you need to either base them on a number that already exists on a particular target record (such as a campaign with a Revenue Goal field) or use some other workaround because the dynamic gauges are based on records, not on metadata.

With a DashboardTarget object you have a convenient place to create records for any gauges you will want to create. The object is built to allow for either manually created and maintained records or records that are automatically updated.

An example of a manual record could be "2023 fundraising target." This is a number that staff arrive at through discussion and is not directly generated from data. Using a manual DashboardTarget you can put in the number and use it on a dashboard. If the goal is changed later due to further discussions all you have to do is change the one record and any dashboards based it on will immediately keep pace.

An auto-updated example would be something like "Enrolled Students." Since students could come and go at any time, you want this record to update itself if/when there are any changes. Then any dashboard gauges based on this number (example: "% of enrolled students with a GPA above 3.5") would automatically readjust the top target when students leave the program.

The DashboardTarget object is relatively simple, with just seven fields to support creating and naming a target, a description, and the SOQL that would be used to auto-update it. There are validation rules to prevent mixing up manually-updated and auto-update records. Note that there is no validation that the values in Object API Name or SOQL Query are valid. If an incorrect object name is in the field then the flow will error when it tries to run the SOQL query. (Having validation that the object API names exist would require a much more complicated implementation, probably with code.)

Included in the unmanaged package are two flows to act on DashboardTarget objects:

  1. DashboardTarget_BeforeSave_Update_SOQL_Query - This is a before save record-triggered flow. Because we wanted to have the ability to have a longer SOQL WHERE clause field than 255 characters, this flow works as though the SOQL Query field were a formula. Whenever a DashboardTarget record's Object API Name or SOQL WHERE clause fields are updated it updates the SOQL Query field to keep it up to date.
  2. TEMPLATE_DashboardTargets_Contact_targets - This is an autolaunched flow that gathers all auto-updated records that use the Contact object and runs their SOQL Query to fill their target. This is meant to be launched by some kind of scheduled automation (see #3.) If you have DashboardTarget records that look at other objects than Contact you will want to copy this flow for each object.
  3. NOT INCLUDED: DashboardTarget_Run_object_updates - In the scratch org repo is a flow that you would use to regularly refresh your automatic targets, presumably as a schedule-triggered flow. As built in the repo I put a pause element of zero hours before the flow calls DashboardTargets_Contact_targets so that it runs asynchronously and SOQL Query limits are reset. There is no flow like this included in the unmanaged package as of this writing because it would require the Contact targets flow, above, to be active upon deployment, which we don't want. However, it's a very easy flow to rebuild (see post-install directions, below.)

The automation in this package has a dependency on UnofficialSF's flow component for using SQOL (https://unofficialsf.com/a-graphical-soql-query-builder-for-flow/) which gets automatically installed in scratch orgs based on this repo. If you want to use this project in a sandbox or in production you will need to install that component before installing DynamicGaugeTargets.


Acknowledgments

The idea for developing this project was sparked by my work with the Academy Group.

Clone this wiki locally