ThoughtSpot acquires Mode to define the next generation of collaborative BI >>Learn More

Embedding a report in Salesforce

Overview

A Mode report can be embedded into a Salesforce page layout as a VisualForce page. The embed can be configured so that the underlying Mode report refreshes whenever the page layout is loaded in Salesforce the report can be run with parameters that are derived from Salesforce objects (e.g., a customer ID). For example:

Embed Mode Reports in Salesforce

Requirements

In order to follow the steps in this guide the following requirements must be met:

  • You must have permissions in Salesforce to create VisualForce objects, change page layouts and access the setup page.
  • The Mode Workspace containing the target report must be on a paid plan.
  • Embed viewers must be logged-in to Mode, must be members of the Mode Workspace containing the embedded report, and must have access to the embedded report.

NOTE: The exact steps outlined in this guide assume you are using the Salesforce Classic interface. You may embed a Mode report using the Salesforce Lightning interface, but the steps below may vary.

Implementation steps

Prepare the report

Begin by creating a report in Mode that displays the data you want to embed inside of Salesforce.

If you want the report to display different output depending on the context in which the embed is viewed in Salesforce, add parameters. In the example below, we use a parameter called organization_id, which represents the unique id of a customer as stored in our internal database. The organization_id corresponding to each customer is stored in Salesforce on the Account object in the custom field OrganizationAccountID__c.

Whenever the page layout containing the embed loads, Salesforce will provide the embed with the value of OrganizationAccountID__c for the corresponding Account. Then the underlying report will run with that value and the embed will render the results for that Account.

Construct an embed URL

Take the URL of the report and add /embed to the end of the URL path, for example:

<!-- Report URL (always shows latest run) -->
https://app.mode.com/[ORG_NAME]/reports/[REPORT_TOKEN]/embed
                                                           ^^^^^^

TIP: In most cases, you will want to use a standard report link and not a static run link when embedding a report in Salesforce. Learn more about the difference between a report link and static run link.

Now add a query string to the report URL to control the any parameters defined in the report. Note:

  • A field-value pair must be provided for each report parameter (if any are defined) or the embed will not render.
  • For parameters with dynamic values based on the context in which the embed is viewed, use a Visualforce Expression in the URL. For example, {!Account.OrganizationAccountID__c} would return the value in the OrganizationAccountID__c custom field on the Account object.
  • Ensure you URL encode any parameter values with special characters (if necessary).

Finally, include run=now in the query string to ensure the embedded report's data is refreshed whenever the embed is viewed in Salesforce. Your embed URL should look like the following:

<!-- Embed URL - General Format -->
https://app.mode.com/[ORG_NAME]/reports/[REPORT_TOKEN]/embed?run=now&param_[PARAM_NAME]={![SF_OBJECT_NAME].[SF_FIELD_NAME]}

<!-- Embed URL - Example -->
https://app.mode.com/octan/reports/2277bhs889d5/embed?run=now&param_organization_id={!Account.OrganizationAccountID__c}

Define the Visualforce Page

  1. Click Setup next to your name in the upper right corner. On the left side under Build -> Develop click Visualforce Pages.
  2. All Visualforce Pages currently defined in your Salesforce instance will be listed. Click the New button at the top of the list.
  3. In the Label field, enter a unique name for your Visualforce Page. Under Visualforce Markup, replace the template code with the following code, with the embed URL you created in the previous step and the standardCotroller property of the <apex:page> set to the name of the relevant Salesforce object:
<!-- Visualforce Markup - General Format -->
<apex:page standardController="[SF_OBJECT_NAME]">
<apex:iframe src="https://app.mode.com/[ORG_NAME]/reports/[REPORT_TOKEN]/embed?run=now&param_[PARAM_NAME]={![SF_OBJECT_NAME].[SF_FIELD_NAME]}"
    scrolling="true"
    frameborder="0"
    />
</apex:page>

<!-- Visualforce Markup - Example -->
<apex:page standardController="Account">
<apex:iframe src="https://app.mode.com/octan/reports/2277bhs889d5/embed?run=now&param_organization_id={!Account.OrganizationAccountID__c}"
    scrolling="true"
    frameborder="0"
    />
</apex:page>

IMPORTANT: Depending on the security settings of users in your Salesforce organization, you may need to grant access to the Visualforce Page you just created to certain user profiles. Learn more about Visualforce Page Security.

Add the Visualforce Page to your desired object's page layout

  1. Within setup, find and edit the page layout where you want the embed to show (e.g., Build -> Customize -> Accounts -> Page Layouts).
  2. At the top of the page layout editor, there is a box on the left with a bunch of options for things you can to your page layout. Select Visualforce Pages.
  3. Create a new section on the page layout by dragging the Section item onto the layout where you want the embed to appear. In the popup, give the new section a name (e.g., Customer Stats), select 1 column, and click OK.
  4. In the same box where you found Section you will find the VisualForce page you created. Drag it into the Section you just added to the layout.
  5. Edit the properties on the Visualforce Object (not the Section) by hovering on it and clicking the wrench icon in the upper right. Change the width and height to your liking.

Your report should now render inside the Visualforce Page every time the corresponding page layout is viewed in Salesforce.

Was this article helpful?

Get more from your data

Your team can be up and running in 30 minutes or less.