function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Benjamin BolopueBenjamin Bolopue 

Use associated Account ID as Report Filter while embedding chart into VisualForce page

I need to insert a Report chart into a VisualForce page on a Custom Object named "Visit Preparation". Simple enough...

Where I'm struggling... I need to filter the Report's chart using the ID of the Account associated (via lookup relationship) with Visit Preparation Records.

I've created a field that pulls the associated Account's ID named "Salesforce_ID__c".

How do I filter the inserted Report Chart's data by the ID shown in the Salesforce_ID__c field?

Thanks in advance!
Best Answer chosen by Benjamin Bolopue
Benjamin BolopueBenjamin Bolopue
So... for those of you reading this that are running into a similar issue, here's what I ended up with to Use associated Account as Report Filter while embedding chart into VisualForce page. NOTE: I'm not using the Account ID as I'd originally wanted to.

<analytics:reportChart reportId="INSERT_REPORT_ID_HERE"
                       hideonerror="true"
                       filter="{column:'Account.Name', operator:'equals', value:'{!Visit_Preparation__c.Account__r.Name}'},{column:'Account.Site', operator:'equals', value:'{!Visit_Preparation__c.Account__r.Site}'}"
                       size="small"></analytics:reportChart>
After giving up on using the ID as the filter, I decided to try filtering on the Account Name and Site fields.

Additionally, I updated the API Version associated with the Custom Controller used for my Visit Preparation Object.

Works like a charm!

All Answers

Anil KamisettyAnil Kamisetty
Hi Benjamin

Looks like you want to have the URL which will run the report for the selected Account Id. Here are the steps, which I would recommend to get to that.

1. Run the report in Salesforce. Let us say the url is https://na1.salesforce.com/00O9000000abcde
2. From step 1, the report Id is 00O9000000abcde
3. On the report, create a filter saying Account Id equal to '' and save the report one more time. If already done with the filter creation, ignore this step
4. Add the following attributes at the end of the url. "?pvo={!Salesforce_ID__c}'. The url becomes https://na1.salesforce.com/00O9000000abcde?pvo={!Salesforce_ID__c}

You need use the url from step 4 for displaying the report output in Visual force page.

Note: If this is helpful, please mark the question as answered so others can benefit too.
Benjamin BolopueBenjamin Bolopue
Thanks for the response Anil!

This would be useful while trying to display the whole Report. All I'm looking to do is show the Report's chart. Currently, I'm using the following code to show it:

<analytics:reportChart reportId=”00Oa0000007sOaO”></analytics:reportChart>

Now, I need to filter it's results to only show data pertaining to the associated Account.

I've gone down the path of trying to add filters via:

<analytics:reportChart reportId=”00Oa0000007sOaO” filter="{column:'Account_ID', operator:'equals', value:'!Salesforce_ID__c'}"></analytics:reportChart>
but I keep getting an error that reads: [For the filter 1: Specify a valid filterable column because Account_ID is invalid.]


Anil KamisettyAnil Kamisetty
Did you create a filter on the report itself to accept the value from the visual force page ?
Benjamin BolopueBenjamin Bolopue
I have... Looks like I'm "On-Hold" until SFDC fixes the bug... https://success.salesforce.com/issues_view?id=a1p30000000T3ZdAAK (https://success.salesforce.com/issues_view?id=a1p30000000T3ZdAAK" target="_blank)

Thanks for taking a look anyway!
Benjamin BolopueBenjamin Bolopue
Upon further inspection... "Known Issue" is reportedly fixed.

Here's what I've done.

- Created a text formula field that populates the Account ID on Cases named "Account_SFID__c"
- Created a text formula field that populates the Account ID on Visit Preparation Records
- Updated the custom controller you helped me with as follows:

Execute a SOQL and fetch the related
    Cases and save it to the List
  */
  private void fetchRelatedCases(){
    RelatedCases =
      [
        SELECT
          Id,
          Record_Type_Name__c,
          CreatedDate,
          Account_SFID__c,
          ClosedDate,
          IsEscalated,
          Status,
          Priority,
          CaseNumber,
          Subject,
          Problem_Statement__c         
        FROM
          Case
        WHERE
          AccountId =
            :CurrentVisitPreparation.Account__c
      ];



- Created a Custom Report for Accounts and Cases containing both a "SFDC_ID__c" field (from Accounts) and an "Account_SFID__c" field (from Cases)
- The Report has a single finter of "Account SFID = "" "

The most recent code I've tried (on the Visit Preparation VF page) is:

<analytics:reportChart reportId="00Oa0000008PXVa" filter="[{column:'Account_SFID__c', operator:'equals', value:'{Salesforce_ID__c}'}]"></analytics:reportChart>



column:'Account_SFID__c' references the Report column that's to be filtered.

value:'{Salesforce__ID__c} is to reference the Visit Preparation Record's text formula field that produced the associated Account's ID.
Benjamin BolopueBenjamin Bolopue
So... for those of you reading this that are running into a similar issue, here's what I ended up with to Use associated Account as Report Filter while embedding chart into VisualForce page. NOTE: I'm not using the Account ID as I'd originally wanted to.

<analytics:reportChart reportId="INSERT_REPORT_ID_HERE"
                       hideonerror="true"
                       filter="{column:'Account.Name', operator:'equals', value:'{!Visit_Preparation__c.Account__r.Name}'},{column:'Account.Site', operator:'equals', value:'{!Visit_Preparation__c.Account__r.Site}'}"
                       size="small"></analytics:reportChart>
After giving up on using the ID as the filter, I decided to try filtering on the Account Name and Site fields.

Additionally, I updated the API Version associated with the Custom Controller used for my Visit Preparation Object.

Works like a charm!
This was selected as the best answer
Advanz  Knowledge System Pvt LtdAdvanz Knowledge System Pvt Ltd
HI Benjamin Bolopue,

 I need to display funnel chart  in account detail page,  based on opportunity  stages under particular account. I created  one formula filed on opportunity say "accounid__C",it has  accouont id of that opportunity.   I created one summary report on opprotunity with filter condition and added  funnel chart .Then Created visual force page to display chart.  I am getting chart ,when I am not using  any filter conditions.   If am using filter  condition  I am getting error [For the filter 1: Specify a valid filterable column because Accounid__c is invalid.]  

I am showing  my code :

<apex:page controller="oppcontroller">
  <analytics:reportChart reportId="00O90000006iiNQ"  filter="[{column:'Accounid__c', operator:'equals', value:'{accid}'}]">
  </analytics:reportChart>
</apex:page>

public class oppcontroller
{
    public id accid{set;get;}
    Public oppcontroller()
    {
        accid=ApexPages.currentPage().getParameters().get('id');
   }
}

Please guide me in ordre to display chart with filter conditions in vf pages
Anil KamisettyAnil Kamisetty
Hi Advanz

You need to be very particular while creating the filter condition, need to maintain the right format.

Did you check to see if the Column API name is captured properly ? I have provided an example below.

filter="{column:'Custom_Object__c.Account__c.Name', operator:'equals', value:'{!Account.Name}'}"
jaw999jaw999
Just using as a starting template 
<analytics:reportChart reportId="00OU0000001rGcq" filter="{column:'Account_ID', operator:'equals', value:'!Salesforce_ID__c'}"></analytics:reportChart>

Gives me:
Error: Unknown component analytics:reportChart

???
Robert FoyRobert Foy
The SFDC docuentation on this component if pathetic.  You would think they would give a basic example.  If you pull down the meta-data from the report in the Force.com IDE, you will be able to see your report column names.  You need to make sure the Id column you want to filter by is a column on the report.  You do not need to actually build a filter on the report for the column, just include the column in the detail of the report.  Here's an example:
<analytics:reportChart reportId="00OM0000000dwx7" size="small"
           filter="{column:'CUST_ID', operator:'equals', value:'{!Location_Master__c.Id}'}"/>

For a custom report it appears the name of the ID column in the report becomes CUST_ID.  If you are looking for the standard Name column for instance, that column on the report becomes CUST_NAME for instance.  Your mileage may vary, so again....use the Force.com IDE to pull down your report meta-data definition and take a look at the column specifications.  Hope this helps!


mayur sawantmayur sawant
Hi all,

How can we use a dynamic report id in <analytics:reportChart> instead of hardcoding it everytime.
Like putting <analytics:reportChart> inside a repeat tag.
I am having a problem in which the Ids are changing but on the page its repeating the report of the first chart only.
Anyone got that issue?
 
antony fernando 17antony fernando 17
i would like user to select the filters for the graph displayed like below how do i  do it? using analytics:reportChart tag. Please help. based on the
Year and month selected by user the graph should display.
User-added image
Geoffrey J FlynnGeoffrey J Flynn
I thought I'd post here just because this thread that comes up on google when I search for filtering <analytics:reportChart> by the Account ID.  After a few false starts here's how I did it.

Here's my report and chart.  Id is just a detail column.  No filters, standard Accounts report type.  I have person accounts on here but doesn't really matter

User-added image

My goal was to embed it as a mobile card on SF1

I was able to filter on ID using this code in the Vf page:
 
<apex:page standardController="Account">
    <analytics:reportChart cacheResults="false" reportId="00Oq0000000KQ2I"
        filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!Account.Id}'}]"
        size="tiny">
    </analytics:reportChart>
</apex:page>

Works like a charm as either an embedded Vf page or a mobile card:
User-added image

Hopefully that helps somebody else
Syed Noormohamad 14Syed Noormohamad 14
HI All,

Above code give the Error:
This developer name is invalid. Provide the developer name for the report that contains the chart.

How to achieve this?