---
schema_version: "1"
id: fa2093e81b7ea2a8e15e5dcdcd738c7574e2cf82ba5f57c8e2d1fd4be0dd2b53
title: Run Reports
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_analytics_run_reports.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_analytics_run_reports.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: a9a984188288d968f24e6485a2df397c221a87d49407de236a219c6d8dd87605
description: You can run a report synchronously or asynchronously through the Salesforce Reports and Dashboards API via Apex.
---
# Run Reports

You can run a report synchronously or asynchronously through the Salesforce Reports and Dashboards API via Apex.

Reports can be run with or without details and can be filtered by setting report metadata. When you run a report, the API returns data for the same number of records that are available when the report is run in the Salesforce user interface.

Run a report synchronously if you expect it to finish running quickly. Otherwise, we recommend that you run reports through the Salesforce API asynchronously for these reasons:

- Long-running reports have a lower risk of reaching the timeout limit when they are run asynchronously.
- The Salesforce Reports and Dashboards API via Apex can handle a higher number of asynchronous run requests at a time.
- Because the results of an asynchronously run report are stored for a 24-hour rolling period, they’re available for recurring access.

## Run a Report Synchronously

To run a report synchronously, use one of the ReportManager.runReport() methods. For example:

// Get the report ID
List <Report> reportList = \[SELECT Id,DeveloperName FROM Report WHERE 
    DeveloperName = 'Closed\_Sales\_This\_Quarter' WITH USER\_MODE\];
String reportId = (String)reportList.get(0).get('Id');

// Run the report
Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true);
System.debug('Synchronous results: ' + results);

## Run a Report Asynchronously

To run a report asynchronously, use one of the ReportManager.runAsyncReport() methods. For example:

// Get the report ID
List <Report> reportList = \[SELECT Id,DeveloperName FROM Report WHERE 
    DeveloperName = 'Closed\_Sales\_This\_Quarter' WITH USER\_MODE\];
String reportId = (String)reportList.get(0).get('Id');

// Run the report
Reports.ReportInstance instance = Reports.ReportManager.runAsyncReport(reportId, true);
System.debug('Asynchronous instance: ' + instance);