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
MrSalesForceMrSalesForce 

<analytics:reportChart filter basic query example

Hi Friends, trying to get a basic   <analytics:reportChart > to work with a filter. Im not a hardcore developer and most solutions got a bit hardcore. This is the code is started off using

<apex:page standardController="Account" standardStylesheets="true">
<apex:form > 
 
Account id test = {!Account.Id}

 <table style="width:100%;">
    <tr>
    <td valign="top" cellpadding="10" border="1">
        <analytics:reportChart showRefreshButton="true" reportId="00O25000000Sg3H" filter="[{column:'Account.Id',operator:'equals',value:'001D000001MITN5IAP'}]" size="small"></analytics:reportChart>
    </td>                                                                                                                          
    <td valign="top"> 
    </td>
    <td valign="top">
    </td>
    <td valign="top"> 
    </td>
 </tr>
</table> 
 
</apex:form>
</apex:page>
 

The code above causes an error message that i was struggeling with for quite some time:

 

Error:
[For the filter 1: Specify a valid filterable column because Account.Id is invalid.]


The reason for this is because the "Account.Id" value is incorrect. I found other examples online that had replaced the dot with underscore character (Account_Id), but that also cases the same error. It turns out that that syntax IS correct, but that the column name is case sensitive and in my case it should be all upper case (ACCOUNT_ID).

The question is how to know what the column name is called in the Analytics Api that is used to render the graph. Here is what I used to debug that.

  1. Open the Developer console.
  2. Drop down menu: Debug + Open Execute Anonymous window.
  3. In the Enter Apax Code window paste the following:
    // Add your report id below
    String reportId = '00O25000000Sg3H'; 
    
    Http http = new Http();
           HttpRequest httpReq = new HttpRequest();
           HttpResponse httpRes = new HttpResponse();      
           httpReq.setMethod('GET');
           httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
           httpReq.setEndpoint(
               URL.getSalesforceBaseUrl().toExternalForm()+
               '/services/data/v29.0/analytics/reports/' + reportId +
               '?includeDetails=true'
           );
           httpRes = http.send(httpReq);
           System.debug(httpRes.getBody());
    
  4. Execute
  5. Click debug only to filter out from the excecution log.
  6. Cut n paste the User_Debug line into a text window of choice
  7. User-added image
  8. Look for reportFilters and find the name of the field next to column: (green below)
  9. User-added image
  10. Using that field name solves the "is invalid error message"
  11.  

But it cases my next error message...

 

Error
You can't view the report chart because its report, report type, or chart has been deleted.


To be continued...


 

<apex:page standardController="Account" standardStylesheets="true">
<apex:form > 
 
Account id test = {!Account.Id}

 <table style="width:100%;">
    <tr>
    <td valign="top" cellpadding="10" border="1">
        <analytics:reportChart showRefreshButton="true" reportId="00O25000000Sg3H" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'001D000001MITN5IAP'}]" size="small"></analytics:reportChart>
    </td>                                                                                                                          
    <td valign="top"> 
    </td>
    <td valign="top">
    </td>
    <td valign="top"> 
    </td>
 </tr>
</table> 
 
</apex:form>
</apex:page>
 


 

MrSalesForceMrSalesForce
Fun fact. When using a custom field the API field name is VERY hard to guess.  
Name test = {!Credit_Group__c.Name}

The field above translates to FK_NAME (!) Easy to guess.... LOL

 <analytics:reportChart reportId="00O25000000Sfwa" filter="[{column:'FK_NAME',operator:'equals',value:'{!Credit_Group__c.Name}'}]" size="small"></analytics:reportChart>
MrSalesForceMrSalesForce

Error
You can't view the report chart because its report, report type, or chart has been deleted. 

This error was solved by:

  1. opening the report folder. 
  2. Click on share
  3. Select public groups
  4. Select "All internal users" (or whoever you wanna share with)
MrSalesForceMrSalesForce

Error:
The report returned no results.


I was confused about this error message as well. First make sure that you have added a chart to the report and that it is shared correctly.
Also, opposite how the old classic URL hacks work, this report should have no filters!  When i removed all filters from the source report then it started working.

Feels like i hit all error messages you could find...