How to filter Report by row limit in Report API?

I need to display report in Visualforce.The report returns more than 1000 results causing an error because visualforce only can display 1000 elements.So I need to limit the result row but I read the document here saying :

standard filters (such as range), filtering by row limit, and cross
filters are unavailable.

Currently I am using simple Apex code to retrieve report as below.Is there workaround to return limited row for this situation.

Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true);


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Add a row limit on the report itself:
Row Limit Screenshot

And You specified in comment that you want to be able to set the row limit dynamically, here’s an anonymous script that can do this, incorporate the logic in your controller(NOTE: This only works if your report already have a rowLimit added on the report):

// Get the report ID
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where DeveloperName = 'MyReport'];
String reportId = (String)reportList.get(0).get('Id');

// Get the report metadata
Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
Reports.ReportMetadata reportMd = describe.getReportMetadata();

// Override Row limits
Reports.TopRows tr =  reportMd.getTopRows();
Integer myRowLimit = 20;
//Run Report
Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd);

Method 2

There are multiple ways to handle this.
1) Set the limit in report
2) Use rows property of apex to limit the iteration
3) Unset/delete the items which are more than 1k

You can chose right solution based on your needs.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x