Monday, September 10, 2018

Einstein Analytics: Embed Dashboard to Salesforce Classic

As you see in the previous blog Embed Report Chart to Page Layout, adding report charts to record detail page is pretty simple. But, embedding Einstein Analytics dashboard to record detail page is different.

You can add Einstein Analytics dashboard to record detail page similar with Report Chart in Classic, but it will not show when you open the same record in Lightning. In this blog, I'll share on adding Einstein Analytics dashboard to record detail page in Classic only.

When you edit the page layout, notice "Wave Analytics Assets" and all available dashboard can be added to the page layout.

But, not as simple as adding report charts to the page layout, when adding Einstein Analytics dashboard to the page layout to show relevant record being viewed, you need to play a bit with JSON to link record Id to Einstein Analytics dashboard.

Here is the complete format of JSON to add in the field mapping, all words in yellow highlight are keywords.
"datasets": {
    "dataset1": [
        {"fields": ["field1"],
           "selection": ["$selection1", "$selection2"],
           "filter": {"operator": "operator1", "values": [["$value1, $value2"], ["$value3", "$value4"]]}
        {"fields": ["field2", "field3"],
           "selection": ["$selection3", "$selection4"]
    "dataset2": [
        {"fields": ["field4"],
           "filter": {"operator": "operator2", "values": ["$value5"]}

Sample: when open account page, auto filter Einstein Analytics dashboard with Account being viewed. Add the JSON into Field mapping of Asset Properties.

Let us analyze the JSON code:
1:  {  
2:   "datasets": {  
3:     "OptyWithAcct": [  
4:      { "fields": ["AccountId"],  
5:        "selection": ["$Id"]  
6:      }  
7:     ]  
8:   }  
9:  }  
- line 2: datasets is the keyword, nothing to change
- line 3: OptyWithAcct is the dataset name
- line 4: fields is a keyword, AccountId is API field name in the dataset
- line 5: selection is a keyword, $Id is the API field name from the object, not from the dataset

Let us see the result:

1. The dashboard is automatically filtered with current Account Id.
2. You need to have Account Id as list filter in the dashboard, otherwise, we can't filter the dashboard.

ReferenceEmbed Analytics Dashboards in Salesforce Classic Pages