Can we detect presence of a 'Chart' in a report for using component?

Salesforce Asked by VarunC on December 4, 2020

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?

2 Answers

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.

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
        //chart not available


Answered by Himanshu on December 4, 2020

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.

Answered by Vamsi Krishna Gosu on December 4, 2020

Add your own answers!

Related Questions

How to get data from dataevents using REST API

1  Asked on January 28, 2021 by user87438


Scroll down is not working report

1  Asked on January 26, 2021 by dearbrother


Wave Analytics — containerId/versionId of a dataset

2  Asked on January 26, 2021 by sitansu-pradhan


Connected App packaging

0  Asked on January 25, 2021 by user85767


AMPSCRIPT: Hide HTML Form after clicking on Submit Button

1  Asked on January 25, 2021 by valarie-simmons


Field update before or after creation of an issue

0  Asked on January 23, 2021 by hermann-our


How to check multiple occurrences in the child records?

1  Asked on January 21, 2021 by mauforsalesforce


Live Agent Credit Card Question – Two Part

1  Asked on January 21, 2021 by stephanie-dorman


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP