Mode Help
Embedding
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:
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.
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
^^^^^^
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 theOrganizationAccountID__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¶m_[PARAM_NAME]={![SF_OBJECT_NAME].[SF_FIELD_NAME]}
<!-- Embed URL - Example -->
https://app.mode.com/octan/reports/2277bhs889d5/embed?run=now¶m_organization_id={!Account.OrganizationAccountID__c}
Define the Visualforce Page
- Click Setup next to your name in the upper right corner. On the left side under Build -> Develop click Visualforce Pages.
- All Visualforce Pages currently defined in your Salesforce instance will be listed. Click the New button at the top of the list.
- 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¶m_[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¶m_organization_id={!Account.OrganizationAccountID__c}"
scrolling="true"
frameborder="0"
/>
</apex:page>
Add the Visualforce Page to your desired object's page layout
- Within setup, find and edit the page layout where you want the embed to show (e.g., Build -> Customize -> Accounts -> Page Layouts).
- 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.
- 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. - 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. - 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?