1

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);
  • 1
    Currently i put Read Only and apex: repeat rows="300" and it solved the problem.I just let this question open just to check other suitable answer. – unidha Jul 21 '16 at 4:58
2

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;
tr.setRowLimit(myRowLimit);
system.debug(tr);
reportMd.setTopRows(tr);
//system.debug(tr);
//Run Report
Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd);
system.debug(results);
  • The requirement is display in visual force.The user can change the limit in the report but in visualforce, we need to have different filter using report API. – unidha Jul 21 '16 at 4:44
  • that wasn't specified :) you can use report metadata to set the TopRows to your desired limit, i added a sample to the answer. – Haytham Jul 21 '16 at 4:55
  • The code is exactly what I need.Previously I thought you suggest to update the filter in the report itself(not report API).Sorry for misunderstanding. – unidha Jul 21 '16 at 6:55
1

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.

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.