Skip to content
Michael Kolodner edited this page Nov 22, 2022 · 28 revisions

This repo 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.

Install Instructions:

If you want to use this project in real life I strongly recommend that you test in a sandbox first!

  1. Make sure that you install the UnofficialSF flow component first or you will get an install error.

  2. Install the unmanaged package:

Post-Install Instructions

  1. The Before-Save flow that keeps SOQL Query updated based on SOQL WHERE Clause installs in a ready-to-use state and active.

  2. The other flow installs as a flow template. Do not activate this. You should Save As to create a new flow before activating your version. (I don't recommend activating the original flow because any later installation of a version of this package will revert the flow to the packaged flow. So any changes you made will be lost.)

  3. Go create your first dashboard with dynamically-set gauges! A Dashboard with Dynamic Gauges

Further Post-Install Ideas

  1. The packaged template DashboardTargets_Contact_targets only updates dashboardtargets that are about contact records. You will want to make versions of this flow for any other objects you or your users are going to have auto-updated dashboardtargets about. (Don't forget to add to the DashboardTargets_Contact_targets whenever you make a flow for updating dashboardtargets about a new object!)

  2. As noted above, there is no packaged template flow to update all dashboardtargets (DashboardTarget_Run_object_updates). So if you want a Schedule Triggered Flow that runs at least once per day to keep auto-updated dashboardtargets up-to-date you'll have to build it yourself. INSTRUCTIONS WILL BE HERE.

  3. You also might want to keep an auto-launched version of that flow, if you build it, and then put a button on the DashboardTarget page layout to update all targets right away. This will allow users to build new auto-update dashboardtargets without having to wait until the next day for them to have a value in Target.

  • You could create a New Action on DashboardTarget that launches this flow, then add that to the page layout.
  • Or you could install the free Launch Flow in Modal from SalesforceLabs and put it on the DashboardTarget Lightning Page for users to click.

A DashboardTargets page with Launch Flow In Modal button

  1. You may want to edit the page layout and/or override the predefined actions on that layout to hide the Change Owner button (if not relevant for your usage) or the Clone button (if you don't want users to be able to clone existing DashboardTarget records.)

Acknowledgments

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

Clone this wiki locally