Automatically Refresh Your Salesforce Dashboard Every Hour or Minute

Automatically Refresh Your Salesforce Dashboard Every Hour or Minute

Last Updated on February 13, 2024 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can you leverage Salesforce Reports and Dashboards REST API to automatically refresh a dashboard every hour or every minute in Salesforce using Salesforce Flow?

Objectives:

After reading this blog, you’ll be able to:

  1. Create a Connected App and Auth Provider.
  2. Create Named Credentials for outbound requests.
  3. Make an outbound HTTP PUT request using Salesforce Flow, eliminating the need for coding.
  4. Manage the outbound request response and implement appropriate actions.
  5. Run an Autolaunched Flow at regular intervals (for example, every 15 minutes, hourly, every four hours, etc.).
  6. Validate the integration and ensure the data flow works correctly.
  7. and much more.

👉 Previously, I’ve penned several posts on the topic of interfacing Salesforce with a diverse range of systems. Why not check them out while you are at it?!

  1. Generate Barcode and QR Code in Salesforce
  2. Integrate Salesforce with OpenWeatherMap Using Salesforce Flow
  3. Verify and Standardize Salesforce Addresses with Google’s Address Validation API
  4. Salesforce and Google’s Time Zone API Integration: Translating Coordinates into Time Zone Info
  5. Proactive Salesforce Monitoring: Periodically Checking if Salesforce is Down with the Salesforce Trust API
  6. Automate Currency Exchange Rate Updates in Salesforce using Currency Exchange API

Business Use case

Madison Campbell currently serves as a Salesforce Architect at Gurukul On Cloud (GoC). Madison has been instrumental in automatically updating current rates from the current Exchange Rate API for multi-currency functionality into Salesforce as part of the Sales Cloud rollout.

Now, the business wants Madison to address another critical item – they want a way to auto-refresh the ‘Sales Dashboard’ every 30 minutes. Currently, Salesforce only allows them to refresh only once.

Refresh a Dashboard

Salesforce offers two methods for updating dashboards: manual refresh and subscription-based refresh (Schedule refresh). The manual refresh option enables users to update their dashboard on demand, pulling the latest data directly from the Salesforce database. Alternatively, users can subscribe to a dashboard, scheduling automatic refreshes on a daily, weekly, or monthly basis. This subscription feature ensures that users regularly receive the most up-to-date information without needing to manually trigger each update.

The subscription-based refresh feature also known as Schedule Refresh, has certain limitations. Notably, it does not provide the flexibility to schedule dashboard refreshes at more frequent intervals such as every hour, every 30 minutes, or even every 6 hours, among other specific time frames. This means users are unable to automate dashboard updates at these shorter intervals.

In this blog post, we will delve deeply into how to address this challenge without writing a single line of code. I encountered this use case when someone posed it in the Trailblazer community. Finding it quite challenging, I was motivated to find a solution.

What is the Salesforce Reports and Dashboards REST API?

The Reports and Dashboards REST API provides programmatic access to your report and dashboard data as defined in the report builder and dashboard builder. This API enables integration of the data into any web or mobile application, both inside and outside the Salesforce platform. For example, it can be used to trigger a Chatter post with a snapshot of top-performing representatives each quarter.

The Reports and Dashboards REST API will revolutionize the way you access and visualize your data. You can:

  • Integrate report data into custom objects.
  • Define rich visualizations on top of the API to animate the data.
  • Build custom dashboards.
  • Automate reporting tasks.

At a high level, the API resources let you query and filter report data. You can:

  • Run tabular, summary, or matrix reports synchronously or asynchronously.
  • Filter for specific data on the fly.
  • Query report metadata.

You can also work with dashboard resources to:

  • Get a list of recently used dashboards.
  • Get dashboard metadata and data.
  • Query dashboard status.
  • Refresh dashboards.

If you want to know more about the Salesforce Reports and Dashboards REST API, please go through the documentation.

How to Refresh a Dashboards Through REST API?

Use a PUT request on the Dashboard Results resource to trigger a dashboard refresh. The refresh response returns the URL of the status resource after the refresh is triggered. If filter parameters are included in the PUT request, only the filtered data will be refreshed.

The following PUT request refreshes the dashboard with the ID of 01ZB0000000hMW3MAM.

/services/data/v59.0/analytics/dashboards/01ZB0000000hMW3MAM

The response contains the status URL for the refreshed dashboard:

{ 
  "statusUrl" : "/services/data/v31.0/analytics/dashboards/01ZB0000000hMW3MAM/status" 
}

Prerequisite

There are multiple prerequisites that need to be met before we can start configuring an HTTPS Callout from a flow.

Step 1: Install Schedul-o-matic 9000 App

The Schedul-o-matic 9000 app offers the flexibility of custom repeat intervals. Whether it’s running a flow once, every 5 minutes indefinitely, or any time frame in between, the choice lies in your hands.

Read this article to understand and get step-by-step instructions, as well as reasons why we’re using the Schedul-o-matic 9000 app.

Step 2: Create a Connected App

A connected app is a framework that enables an external application to integrate with Salesforce using APIs and standard protocols, such as SAML, OAuth, and OpenID Connect. Connected apps use these protocols to authenticate, authorize, and provide single sign-on (SSO) for external apps. 

  1. Click Setup.
  2. In the Quick, enter Apps in the Quick Find box, and select App Manager.
  3. Click New Connected App.
  4. Enter the following details: 
    1. Connected App Name: SF REST API 
    2. Contact Email: Email Address
    3. Enabled OAuth Settings: Checked
    4. Callback URLs: https://localhost/callback
      1. Remember that the Callback URL is https://localhost/callback for now – this will be changed in a subsequent step when we create an Auth Provider.
    5. Selected OAuth Scope: Select the one that applies to your business use case.
    6. Require Secret for Web Server Flow: Checked
    7. Require Secret for Refresh Token Flow: Checked
  5. Click Save.
  6. Make a note of the Consumer Key and Consumer Secret; we will need this for the next step.

Step 3: Create an Auth Provider

  1. Click Setup.
  2. In the Quick, enter Auth. Providers in the Quick Find box, and select Auth. Providers.
  3. Click New.
  4. Select Salesforce as Provider Type.
    1. Give your Auth Provider a name and paste the Consumer Key and Consumer Secret from your Connected App.
  5. Click Save.
  6. Copy the Callback URL, open the Connected App created in step #2, and replace the dummy Callback URL from the Auth provider with it.

Step 4: Create a Named Credential

  1. Click Setup.
  2. In the Quick Find box, enter Named Credentials, and then select Named Credentials.
  3. Click New Legacy.
  4. Fill out the page with the callout endpoint’s URL and authentication parameters.
    1. Enter the hostname portion of the Callback URL here. This means you should paste the entire Callback URL and then remove the section that begins with services/authcallback/CallMeBack_AuthProvider.
  5. Click Save.
  6. After saving, the you will be redirected to login. When you log back in, you will get the following message, press the Allow button.

Automation Champion Approach (I-do):

While this can be solved using various automation tools like Scheduled Apex, AppExchange App and others, we will use Salesforce Flow and newly introduced HTTP PUT Callout flow feature.

HTTP Callout pulls or sends data between the Salesforce database and an external system via Flow Builder without using code. You can set up direct integrations as needed without having to work with a developer or call a middleware tool, such as Mulesoft. After you configure the HTTP callout action in a flow, Flow Builder auto-generates an external service registration, an invocable action, and Apex class that you can use to create an Apex-defined resource for flows. You can then use the data output of the API request as input within Flow Builder and across Salesforce.

You can use HTTP Callout to connect a flow to a variety of APIs.

  • Get address information using a map API
  • Get weather conditions with a weather service API
  • Generate the barcode with a barcode service API
  • Get payment authorization information with a payment processing API
  • Refresh Salesforce Dashboard Using REST API
  • and much more

Before discussing the solution, let me show you a diagram of the process at a high level. Please spend a few minutes going through the following Flow diagram to understand it.

Guided Practice (We-do):

There are 5 steps to solve Madison’s business requirement using Autolaunched Flow. We must:

  1. Define flow properties for the autolaunched flow.
  2. Add a Get Record element to find the Sales Dashboard details 
  3. Add a Decision element to check if the Sales Dashboard was found or not.
  4. Configure an HTTP PUT callout for Report and Dashboard REST API
  5. Schedule the Flow to Run Every 30 Minutes

Step 1: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Autolaunched Flow (No Trigger)option.
  5. Click on Create.

Step 2: Adding a Get Record Element to Find the Sales Dashboard Details 

The next step is to use the Get Records element to find the Sales Dashboard Details. 

  1. On Flow Designer, Click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Dashboard object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Title
      2. Operator: Equals
      3. Value: Sales Dashboard 
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click the X at the top to save your changes.

Step 3: Using Decision Element to Check If the Pending Approval Was Found or Not

Now, we will use the Decision element to check if the previous Get Records element returns Dashboard details for a given Sales Dashboard. 

  1. On Flow Designer, click on the+icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Dashboard}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. Click Done.

Step 4: Configure an HTTP PUT callout for Report and Dashboard REST API

HTTP Callout guides you through entering the details about the HTTP web-based service or REST API endpoint you’re connecting to. After you complete the configuration, you invoke the action in a flow.

  1. On Flow Designer, below the Yes node, click on the +icon and select the Action element.
  2. Click + Create HTTP Callout.
  3. Configure the external service that connects Salesforce to the HTTP-based API.
    1. Enter a Name for the external service.
    2. Select the named credential that you created in Step 4 (Prerequisite).
    3. Click Next.
  4. The next step is configuring the invocable action that you can use in Flow Builder or across Salesforce.
    1. For Label, enter the action that the callout performs.
    2. Method: PUT
    3. Add the URL endpoint for the request.
      1. URL Path: /services/data/v31.0/analytics/dashboards/{DashboardID}
      2. Data Type: String
      3. Description: The ID of the dashboard to be refreshed
    4. Click Next.
    5. Click Next.
    6. For Sample Response Method select Connect for Schema.
      1. Click Next.
      2. Paste Sales Dashboard Id in DashboardID key. 
      3. Click Connect.
      4. If successful, you will receive a response. Make sure to confirm that the Apex data structure is correct.
    7. Click Save.
  5. Flow Builder creates the action and external service. The action is available in the Actions window in the flow.
  6. The next step is to add the apex action generated by the HTTP Callout setup in the previous steps. We will use the Action element.
    1. Label the new action Refresh Dashboard.
    2. Set Input Values
      1. DashboardID: {!Get_Dashboard.Id}
  7. Click Done.

In the end, Madison’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label (Refresh Dashboard) the API Name will auto-populate.
  3. API Version for Running the Flow: 60
  4. Click Done.

Step 5: Schedule the Flow to Run Every 30 Minutes

Now, we will use the Schedul-o-matic 9000 app to run the auto-launched flow we just created every 30 minutes. 

Proof of Concept

From now on, the auto-launched flow we created, will run every 30 minutes using the Schedul-o-matic 9000 app to refresh the Sales Dashboard. I have been running this flow for the last three weeks, and it has been working without any issues.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Preferred Timing(required)

23 thoughts on “Automatically Refresh Your Salesforce Dashboard Every Hour or Minute

  1. I have error : BAD_REQUEST”, “message”: “The current user of this dashboard is inactive. Your system administrator must select an active user for this dashboard.”}])

    It’s me, the current user Administrator !!

  2. hi, I have this error :

    BAD_REQUEST”, “message”: “The current user of this dashboard is inactive. Your system administrator must select an active user for this dashboard.”}])

    The current user its me administartor !!

  3. Hi Rakesh, I set this up and it works for me, but it does not work for other people.

    I tested with another admin account in our org. Specifically, for other users, the flow finds the correct dashboard and says it runs the Refresh Dashboard REST API flow action, but the dashboard is not actually refreshing for them. I assume it has to do with the API. Do you know what might cause this?

  4. Followed all of the above steps. Can run and debug the flow with no errors however the dashboard is not being refreshed. On the action element when debugging the flow I see the following:

    2XX (RefreshDashboard_Dashboardx20RESTx20API_OUT_2XX : { “statusUrl_set” : true, “statusUrl” : “/services/data/v31.0/analytics/dashboards/SALESFORCEID/status” })

    responseCode (201)

  5. I have followed all the steps listed and I am able to Run and Debug the flow with no errors. The issue is nothing happens when the flow runs. The dashboard does not refresh. Am I missing something? When I debug the flow I see the following output on the Refresh Dashboard Action:
    2XX (RefreshDashboard_Dashboardx20RESTx20API_OUT_2XX : { “statusUrl_set” : true, “statusUrl” : “/services/data/v31.0/analytics/dashboards/SALESFORCEID/status” })
    responseCode (201)

    I am also able to log into workbench and use the PUT request example listed at the top of the article and refresh my dashboard that way.

  6. Hi Rakesh,

    I tried your approach but i am receiving “”[{\”message\”:\”Session expired or invalid\”,\”errorCode\”:\”INVALID_SESSION_ID\”}]” error after configuring till Step 4: Configure an HTTP PUT callout for Report and Dashboard REST API. Can you please brief about named credential configuration that you did your org?

  7. Getting error: OAUTH_APPROVAL_ERROR_GENERIC : An unexpected error has occured during authentication. Please try again.

  8. Will this also work if the dashboard is open on the screen?
    My scenario is that I would like to see live metrics along the day with a 30 min refresh

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading