[SalesForce] Get more than 2000 record from report in Apex

I want to retrieve more than 2000 records from reports using apex code. I read saleforce report limitation and found 2 different thing.

  1. The API returns up to the first 2,000 report rows.
  2. The number of report rows processed during a synchronous report run count towards the governor limit that restricts the total number of rows retrieved by SOQL queries to 50,000 rows per transaction. This limit is not imposed when reports are run asynchronously.

So that how to implement second point?

Best Answer

you can use a filter on the object id column to exclude the first 2000 results and get the second 2000 until you fetch all the data:

    Reports.ReportResults results = Reports.ReportManager.runReport('00O58000003sea0',true);
    // pars the result to recive the first 2000 ids.
    Reports.ReportFilter RF = new Reports.ReportFilter('ACCOUNT_ID', 'notEqual', ConcatOfReturnIds);
    Reports.ReportMetadata RM = results.getReportMetadata();
    list<Reports.ReportFilter>allfilters = new list<Reports.ReportFilter> {RF};
    allfilters.addAll(RM.getReportFilters());
    RM.setReportFilters(allfilters);
    results = Reports.ReportManager.runReport('00O58000003sea0', RM,true);
    System.debug(LoggingLevel.INFO,'res: '+results.getFactMap());

for more information see here Glazeforce but don't use the callouts - its use less. regards.

Related Topic