AnswerBun.com

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.
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
    }

}

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

Apex Regex Extract Numeric Value from String

3  Asked on January 6, 2022 by yossi-cadaner

 

Ignore files when force:source:convert

4  Asked on January 6, 2022 by simonp

 

AuthToken using Open Id Connect

1  Asked on January 6, 2022 by bergin-panimayam

     

Using IsPickVal() function inside Email Templates

1  Asked on January 6, 2022 by anthony-williams

       

Create record by submitting string for reference field

1  Asked on January 4, 2022 by user85715

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir