Newer Version Available

This content describes an older version of this product. View Latest

Run Reports Synchronously or Asynchronously

Get summary data with or without details by running a report synchronously or asynchronously through the API. 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 API asynchronously for these reasons:

  • Long running reports have a lower risk of reaching the timeout limit when run asynchronously.

  • The 2-minute overall Salesforce API timeout limit doesn’t apply to asynchronous runs.

  • The Salesforce1 Reporting API can handle a higher number of asynchronous run requests at a time.

  • Since the results of an asynchronously run report are stored for a 24-hr rolling period, they’re available for recurring access.

To run a report synchronously:

  • Send a GET or POST request to the Execute Sync resource to get data.
  • Use a POST request to get specific results on the fly by passing filters in the report metadata.

To fetch report data asynchronously:

  1. Send a POST request to the Execute Async resource. If you’re passing filters, include them in the POST request metadata. The request returns the instance ID where results of the run are stored.

  2. Send a GET request to the Instance Results resource to fetch data using the instance ID.

Example of a synchronous report run

This GET request to the Execute Sync resource, /services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK?includeDetails=true, for a synchronous run returns summary data with details.

1{
2    "hasDetailRows": true,
3    "attributes": {
4        "instancesUrl": "/services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK/instances",
5        "describeUrl": "/services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK/describe",
6        "type": "Report",
7        "reportId": "00OD0000001ZbP7MAK",
8        "reportName": "Stuck Opportunities"
9    },
10    "groupingsDown": {
11        "groupings": [
12...
13        ]
14    },
15    "groupingsAcross": {
16        "groupings": [
17...
18        ]
19    },
20    "reportExtendedMetadata": {
21...
22    },
23    "allData": true,
24    "reportMetadata": {
25        "name": "Stuck Opportunities",
26        "id": "00OD0000001ZbP7MAK",
27        "currency": null,
28        "developerName": "StuckOpportunities",
29        "groupingsDown": [
30            {
31                "name": "ACCOUNT_NAME",
32                "sortOrder": "Asc",
33                "dateGranularity": "None"
34            },
35            {
36                "name": "CLOSE_DATE",
37                "sortOrder": "Desc",
38                "dateGranularity": "FiscalQuarter"
39            }
40        ],
41        "groupingsAcross": [
42            {
43                "name": "STAGE_NAME",
44                "sortOrder": "Desc",
45                "dateGranularity": "None"
46            },
47            {
48                "name": "ACCOUNT_LAST_ACTIVITY",
49                "sortOrder": "Asc",
50                "dateGranularity": "Week"
51            }
52        ],
53        "reportType": {
54            "type": "Opportunity",
55            "label": "Opportunities"
56        },
57        "aggregates": [
58            "s!EXP_AMOUNT",
59            "FORMULA1",
60            "RowCount"
61        ],
62        "reportFormat": "MATRIX",
63        "reportBooleanFilter": null,
64        "reportFilters": [
65            {
66                "value": "Closed Won,Closed Lost",
67                "column": "STAGE_NAME",
68                "operator": "notEqual"
69            },
70            {
71                "value": "50",
72                "column": "PROBABILITY",
73                "operator": "greaterThan"
74            }
75        ],
76        "detailColumns": [
77            "OPPORTUNITY_NAME",
78            "PROBABILITY",
79            "EXP_AMOUNT",
80            "NEXT_STEP",
81            "BucketField_34840671"
82        ]
83    },
84    "factMap": {
85...
86        "4_0!0_2": {
87            "rows": [
88                {
89                    "dataCells": [
90                        {
91                            "value": "006D000000CrRLxIAN",
92                            "label": "DFC Inc. - 10K"
93                        },
94                        {
95                            "value": 90,
96                            "label": "90%"
97                        },
98                        {
99                            "value": {
100                                "amount": 9450,
101                                "currency": null
102                            },
103                            "label": "$9,450.00"
104                        },
105                        {
106                            "value": "Signed SOW",
107                            "label": "Signed SOW"
108                        },
109                        {
110                            "value": "Chemicals",
111                            "label": "Chemicals"
112                        }
113                    ]
114                }
115            ],
116            "aggregates": [
117                {
118                    "value": 9450,
119                    "label": "$9,450.00"
120                },
121                {
122                    "value": 9450,
123                    "label": "9,450.00"
124                },
125                {
126                    "value": 1,
127                    "label": "1"
128                }
129            ]
130        },
131...
132        "4_1!0_2": {
133            "rows": [
134                {
135                    "dataCells": [
136                        {
137                            "value": "006D000000CrRLyIAN",
138                            "label": "DFC Inc. - 12K"
139                        },
140                        {
141                            "value": 90,
142                            "label": "90%"
143                        },
144                        {
145                            "value": {
146                                "amount": 10800,
147                                "currency": null
148                            },
149                            "label": "$10,800.00"
150                        },
151                        {
152                            "value": "Signed SOW",
153                            "label": "Signed SOW"
154                        },
155                        {
156                            "value": "Chemicals",
157                            "label": "Chemicals"
158                        }
159                    ]
160                }
161            ],
162            "aggregates": [
163                {
164                    "value": 10800,
165                    "label": "$10,800.00"
166                },
167                {
168                    "value": 10800,
169                    "label": "10,800.00"
170                },
171                {
172                    "value": 1,
173                    "label": "1"
174                }
175            ]
176        },
177...
178    }
179}

Example of an asynchronous report run

  1. This is a POST request, /services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK/instances, to the Execute Async resource for an asynchronous run requesting summary results.
    1{
    2    "reportMetadata": {
    3        "name": "StuckOpportunities",
    4        "id": "00OD0000001ZbP7MAK",
    5        "currency": null,
    6        "developerName": "StuckOpportunities",
    7        "reportType": {
    8            "type": "Opportunity",
    9            "label": "Opportunities"
    10        },
    11        "aggregates": [
    12            "s!EXP_AMOUNT",
    13            "FORMULA1",
    14            "RowCount"
    15        ],
    16        "groupingsDown": [
    17            {
    18                "name": "ACCOUNT_NAME",
    19                "sortOrder": "Asc",
    20                "dateGranularity": "None"
    21            },
    22            {
    23                "name": "CLOSE_DATE",
    24                "sortOrder": "Desc",
    25                "dateGranularity": "FiscalQuarter"
    26            }
    27        ],
    28        "groupingsAcross": [
    29            {
    30                "name": "STAGE_NAME",
    31                "sortOrder": "Desc",
    32                "dateGranularity": "None"
    33            },
    34            {
    35                "name": "ACCOUNT_LAST_ACTIVITY",
    36                "sortOrder": "Asc",
    37                "dateGranularity": "Week"
    38            }
    39        ],
    40        "reportFormat": "MATRIX",
    41        "reportFilters": [
    42            {
    43                "value": "Closed Won,Closed Lost",
    44                "column": "STAGE_NAME",
    45                "operator": "notEqual"
    46            },
    47            {
    48                "value": "50",
    49                "column": "PROBABILITY",
    50                "operator": "greaterThan"
    51            }
    52        ],
    53        "detailColumns": [
    54            "OPPORTUNITY_NAME",
    55            "PROBABILITY",
    56            "EXP_AMOUNT",
    57            "NEXT_STEP",
    58            "BucketField_34840671"
    59        ],
    60        "reportBooleanFilter": null
    61    }
    62}

    The response to the POST request returns the instance handle that stores the summary results of the run.

    1{
    2    "id": "0LGD000000000IjOAI",
    3    "requestDate": "2013-08-12T18:39:06Z",
    4    "status": "New",
    5    "ownerId": "005D0000001KvxRIAS",
    6    "url": "/services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK/instances/0LGD000000000IjOAI",
    7    "hasDetailRows": false,
    8    "completionDate": null
    9}
  2. A GET request, /services/data/v29.0/analytics/reports/00OD0000001ZbP7MAK/instances/0LGD000000000IjOAI, to the Instance Results resource for the instance handle fetches the report results.
    1{
    2    "hasDetailRows": false,
    3    "attributes": {
    4        "id": "0LGD000000000IjOAI",
    5        "requestDate": "2013-08-12T18:39:06Z",
    6        "status": "Success",
    7        "ownerId": "005D0000001KvxRIAS",
    8        "completionDate": "2013-08-12T18:39:07Z",
    9        "type": "ReportInstance",
    10        "reportId": "00OD0000001ZbP7MAK",
    11        "reportName": "Stuck Opportunities"
    12    },
    13    "groupingsDown": {
    14        "groupings": [
    15...
    16        ]
    17    },
    18    "groupingsAcross": {
    19        "groupings": [
    20            {
    21                "value": "Negotiation/Review",
    22                "key": "0",
    23                "label": "Negotiation/Review",
    24                "groupings": [
    25                    {
    26                        "value": null,
    27                        "key": "0_0",
    28                        "label": "-",
    29                        "groupings": []
    30                    },
    31                    {
    32                        "value": "2012-07-08",
    33                        "key": "0_1",
    34                        "label": "7/8/2012 - 7/14/2012",
    35                        "groupings": []
    36                    },
    37                    {
    38                        "value": "2013-07-14",
    39                        "key": "0_2",
    40                        "label": "7/14/2013 - 7/20/2013",
    41                        "groupings": []
    42                    }
    43                ]
    44            },
    45...
    46        ]
    47    },
    48    "reportExtendedMetadata": {
    49        "detailColumnInfo": {
    50            "OPPORTUNITY_NAME": {
    51                "label": "Opportunity Name",
    52                "dataType": "string"
    53            },
    54            "PROBABILITY": {
    55                "label": "Probability (%)",
    56                "dataType": "percent"
    57            },
    58            "EXP_AMOUNT": {
    59                "label": "Expected Revenue",
    60                "dataType": "currency"
    61            },
    62            "NEXT_STEP": {
    63                "label": "Next Step",
    64                "dataType": "string"
    65            },
    66            "BucketField_34840671": {
    67                "label": "Industry",
    68                "dataType": "string"
    69            }
    70        },
    71        "aggregateColumnInfo": {
    72            "RowCount": {
    73                "label": "Record Count",
    74                "dataType": "int",
    75                "downGroupingContext": null,
    76                "acrossGroupingContext": null
    77            },
    78            "FORMULA1": {
    79                "label": "formula1",
    80                "dataType": "double",
    81                "downGroupingContext": "ALL_SUMMARY_LEVELS",
    82                "acrossGroupingContext": "ALL_SUMMARY_LEVELS"
    83            },
    84            "s!EXP_AMOUNT": {
    85                "label": "Sum of Expected Revenue",
    86                "dataType": "currency",
    87                "downGroupingContext": null,
    88                "acrossGroupingContext": null
    89            }
    90        },
    91        "groupingColumnInfo": {
    92            "CLOSE_DATE": {
    93                "label": "Close Date",
    94                "dataType": "date",
    95                "groupingLevel": 1
    96            },
    97            "STAGE_NAME": {
    98                "label": "Stage",
    99                "dataType": "picklist",
    100                "groupingLevel": 0
    101            },
    102            "ACCOUNT_NAME": {
    103                "label": "Account Name",
    104                "dataType": "string",
    105                "groupingLevel": 0
    106            },
    107            "ACCOUNT_LAST_ACTIVITY": {
    108                "label": "Account: Last Activity",
    109                "dataType": "date",
    110                "groupingLevel": 1
    111            }
    112        }
    113    },
    114    "allData": true,
    115    "reportMetadata": {
    116        "name": "Stuck Opportunities",
    117        "id": "00OD0000001ZbP7MAK",
    118        "currency": null,
    119        "developerName": "StuckOpportunities",
    120        "groupingsDown": [
    121            {
    122                "name": "ACCOUNT_NAME",
    123                "sortOrder": "Asc",
    124                "dateGranularity": "None"
    125            },
    126            {
    127                "name": "CLOSE_DATE",
    128                "sortOrder": "Desc",
    129                "dateGranularity": "FiscalQuarter"
    130            }
    131        ],
    132        "groupingsAcross": [
    133            {
    134                "name": "STAGE_NAME",
    135                "sortOrder": "Desc",
    136                "dateGranularity": "None"
    137            },
    138            {
    139                "name": "ACCOUNT_LAST_ACTIVITY",
    140                "sortOrder": "Asc",
    141                "dateGranularity": "Week"
    142            }
    143        ],
    144        "reportType": {
    145            "type": "Opportunity",
    146            "label": "Opportunities"
    147        },
    148        "aggregates": [
    149            "s!EXP_AMOUNT",
    150            "FORMULA1",
    151            "RowCount"
    152        ],
    153        "reportFormat": "MATRIX",
    154        "reportBooleanFilter": null,
    155        "reportFilters": [
    156            {
    157                "value": "Closed Won,Closed Lost",
    158                "column": "STAGE_NAME",
    159                "operator": "notEqual"
    160            },
    161            {
    162                "value": "50",
    163                "column": "PROBABILITY",
    164                "operator": "greaterThan"
    165            }
    166        ],
    167        "detailColumns": [
    168            "OPPORTUNITY_NAME",
    169            "PROBABILITY",
    170            "EXP_AMOUNT",
    171            "NEXT_STEP",
    172            "BucketField_34840671"
    173        ]
    174    },
    175    "factMap": {
    176        "4_0!2_0": {
    177            "aggregates": [
    178                {
    179                    "value": 0,
    180                    "label": "$0.00"
    181                },
    182                {
    183                    "value": null,
    184                    "label": "-"
    185                },
    186                {
    187                    "value": 0,
    188                    "label": "0"
    189                }
    190            ]
    191        },
    192        "12_0!4": {
    193            "aggregates": [
    194                {
    195                    "value": 0,
    196                    "label": "$0.00"
    197                },
    198                {
    199                    "value": null,
    200                    "label": "-"
    201                },
    202                {
    203                    "value": 0,
    204                    "label": "0"
    205                }
    206            ]
    207        },
    208...
    209    }
    210}