3

When using the component I'm receiving following error due to a chart not present in the report, be cause I verified Report exists and is public shared and report types are valid (Summary/Matrix), which are allowed Formats:

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

So my query is, can we detect programatically, in Apex, if Report has an embedded chart in it?

3
  • you can use metadata API to check if report has a chart or not.
    – Himanshu
    Jan 6, 2016 at 9:27
  • I would like to remain in context of visualforce and apex only. I'm looking through Analytics APi docs but could not find anything regarding chart detection.
    – VarunC
    Jan 6, 2016 at 11:57
  • yes that is under the context of apex because this information is not available from Analytics API. Let me grab sample code for that.
    – Himanshu
    Jan 6, 2016 at 14:37

2 Answers 2

0

I believe you want to show a chart if there's a chart on the report, otherwise you don't want to show anything (not even the error).

If that's the case you can use the attribute hideOnError on the analytics:reportChart component

if you set this attribute to true, if the report doesn't have a chart, then you won't see the error.

3
  • Yes I know, but that only hides the chart but leave the canvas space displayed as blank white space box. For example, if we do multiple analytics:reportChart in a repeat tag then with this setting turn on if chart at index #2 fails, then there will be a blank space between chart #1 and chart #3, which is also not ideal.
    – VarunC
    Jan 6, 2016 at 11:59
  • you can use JS / jQuery to hide the blocks with no charts.. Jan 7, 2016 at 0:29
  • Yes good idea, though, we'll need a callback interface on charts to make sure our JS function fire after charts component have loaded.
    – VarunC
    Jan 7, 2016 at 9:36
0

Salesforce from Metadata API can be used to detect if report contains any chart or not. here is sample piece of code I am sharing which can give you a head start.

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();


String[] reportNames = new String[]{};

//query the report
Report r : [Select OwnerId,NamespacePrefix,Name, Id, DeveloperName, Description 
                                From Report where Id =:'YOUR REPORT id']
reportName = 'unfiled$public'+'/' + r.DeveloperName; 
//add to report list so that multiple report data can be fetched.
reportNames.add(reportName);

for(MetadataService.Metadata reportData :  service.readMetadata('Report',reportNames).getRecords())
{
    MetadataService.Report reportData1 = (MetadataService.Report)reportData;
    if(reportIdName.containsKey(reportData1.fullName) && reportData1.chart != null){
            //CHART AVAILABLE
    }
    else
    {
        //chart not available
    }

}
3
  • thnx for this, but wouldn't using metadata api require to setup an EndPoint to self-organization? Which will require manual setup because we can't work that out in managed package installer?
    – VarunC
    Jan 7, 2016 at 9:38
  • yes you need to setup EndPoint. but you can also create that using apex. (google it and you will find the solution for that.)
    – Himanshu
    Jan 7, 2016 at 9:39
  • yes I know about that, but that is kind of a hack, and salesforce's security review team will not pass that :-)
    – VarunC
    Feb 15, 2016 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .