I've been doing some work on gathering info from a report using its metadata in apex. In this picture is basically what I want to extract:

enter image description here

Currently, I am confused as to why my method for getting the standard filters is returning nothing. Below is my code on what I have so far.

// Get the report ID and folderName
List <Report> reportInfo = [SELECT ID, FolderName FROM Report where Name = 'Some New Report'];

// Get report ID
String reportId = (String)reportInfo.get(0).get('Id');

// Use report ID to get report Metadata
Reports.ReportMetadata metadata = Reports.ReportManager.describeReport(reportId).getReportMetadata();

// this line is the problem
System.debug('Standard Filters: ' + metadata.getStandardFilters());

The very last line simply returns () . I tried adding getName() and getValue() to the end of it but it gives me an error. Any help is much appreciated. Thanks.

  • 1
    Are you sure you're using standard filters in that report? There's getStandardDateFilters for start/end date and date ranges and getReportFilters() for each custom filter in the report. Jan 12 at 19:44
  • Yes that is what I am trying to do. I have also added a picture as to what info I am trying to obtain.
    – apexdev
    Jan 12 at 20:51

That's because you have zero standard filters on that report.

Standard filters vary by report type. For example, standard filters for reports on the Opportunity object are Show, Opportunity Status, and Probability.

Based on your screenshot,

  • Show Me is scope which you can see in the Report metadata. You can get this with getScope()

Defines the scope of data on which you run the report. For example, whether you want to run the report against all opportunities, opportunities you own, or opportunities your team owns. Valid values depend on the reportType. For example, for Accounts reports:

  • MyAccounts
  • MyTeamsAccounts
  • AllAccounts
  • Created Date, as it's a date filter that was provided with the report automatically, will be returned by getStandardDateFilters() which has a distinction from standard filters.

Contains information about standard date filter available in the report—for example, the API name, start date, and end date of the standard date filter duration as well as the API name of the date field on which the filter is placed.

Any other filters you customize on that report will be retrieved with getReportFilters()

  • Great, thanks for the help.
    – apexdev
    Jan 13 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.