Sebastian Scholl
Sebastian Scholl

Reputation: 1105

Getting All Leads belonging to a Report in Salesforce via Salesforce API

This question was asked in 2013 and said to not be supported. I'm hoping that it's been supported in the past 8 years...

Hi There

I'm new to the Salesforce ecosystem/API and having some trouble handling the following requirement of my project (Project X).

The system I'm working on needs to query Leads from Salesforce. It also requires the ability to filter the Leads queried from Salesforce. Instead of building a filtering functionality on our project's side, it seems better to utilize Report's in Salesforce so that the user has the best filtering options available to them (those maintained by Salesforce). The flow would go like this:

  1. A user creates a Report in Salesforce, which returns a list of Leads.
  2. The user logs into Project X and selects one Report from a list of Reports that already exist in their Salesforce account.
  3. Project X is then able to fetch all the Leads returned by the selected Report via the Salesforce API.

I've been able to find documentation for getting Leads OR Reports back from the Salesforce API. However, I've not been able to find anything that explains how to get back the Leads that are returned by a specific Report.

Any help/guidance would be greatly appreciated.

Thank you!

Upvotes: 2

Views: 816

Answers (1)

booky99
booky99

Reputation: 1456

It looks like its supported now. https://developer.salesforce.com/docs/atlas.en-us.api_analytics.meta/api_analytics/sforce_analytics_rest_api_get_reportdata.htm

To summarize, /services/data/v35.0/analytics/reports/00OR0000000K2UeMAK?includeDetails=true is a synchronous endpoint you can use to get what you're asking for. Below is an example response payload. You're asking for Rows -> dataCells. reportExtendedMetadata contains all the high level metadata details behind it for your caching.

{
  "attributes" : {     
    "describeUrl" :
      "/services/data/v35.0/analytics/reports/00OR0000000K2UeMAK/describe",     
    "instancesUrl" :
      "/services/data/v35.0/analytics/reports/00OR0000000K2UeMAK/instances",     
    "reportId" :
      "00OR0000000K2UeMAK",     
    "reportName" : "Deals Closing This Quarter",     
    "type" : "Report" 
  },   
  "allData" : true,   
  "factMap" : {     
    "2!0_0" : {       
      "aggregates" : [ 
        { "label" : "$16,000.01", "value" : 16000.010000000000218278728425502777099609375 }, 
        { "label" : "$16,000.01", "value" : 16000.010000000000218278728425502777099609375 }, 
        { "label" : "1", "value" : 1 } ],       
      "rows" : [ {         
        "dataCells" : [ 
          { "label" : "Acme - 200 Widgets", "value" : "006R00000023IDYIA2" }, 
          { "label" : "$16,000.01",           
            "value" : { "amount" : 16000.01, "currency" : null } }, 
          { "label" : "Word of mouth", "value" : "Word of mouth" }, 
          { "label" : "Need estimate", "value" : "Need estimate" }, 
          { "label" : "60%", "value" : 60}, 
          { "label" : "Q3-2015", "value" : "Q3-2015" }, 
          { "label" : "12", "value" : 12 }, 
          { "label" : "7/31/2015", "value" : "2015-07-31" }, 
          { "label" : "Fred Wiliamson", "value" : "005R0000000Hv5rIAC" }, 
          { "label" : "-", "value" : null } ]       
      } ]     
    },     
    "T!0" : {
      "aggregates" : [ 
        { "label" : "$32,021.01", "value" : 32021.00999999999839928932487964630126953125 }, 
        { "label" : "$16,010.51", "value" : 16010.504999999999199644662439823150634765625 }, 
        { "label" : "2", "value" : 2 } ],       
      "rows" : [ ]      
    },    
...    
     "T!T" : {
      "aggregates" : [ 
        { "label" : "$153,042.01", "value" : 153042.01000000000931322574615478515625 }, 
        { "label" : "$25,507.00", "value" : 25507.00166666666700621135532855987548828125 }, 
        { "label" : "6", "value" : 6 } ],       
      "rows" : [ ]     
    },
...
  "groupingsAcross" : { 
    "groupings" : [ 
      { 
        "groupings" : [ 
          { "groupings" : [ ], "key" : "0_0", "label" : "Existing Business", "value" : "Existing Business" } ],       
        "key" : "0",       
        "label" : "July 2015",       
        "value" : "2015-07-01"
      }, 
      { 
        "groupings" : [ 
          { "groupings" : [ ], "key" : "1_0", "label" : "Existing Business", "value" : "Existing Business" }, 
          { "groupings" : [ ], "key" : "1_1", "label" : "New Business", "value" : "New Business" } ],       
        "key" : "1",       
        "label" : "August 2015",       
        "value" : "2015-08-01"
      }, 
      {       
        "groupings" : [ 
          { "groupings" : [ ], "key" : "2_0", "label" : "Existing Business", "value" : "Existing Business" } ],       
        "key" : "2",       
        "label" : "September 2015",       
        "value" : "2015-09-01"     
      } 
    ]   
  },   
  "groupingsDown" : {
    "groupings" : [ 
      { "groupings" : [ ], "key" : "0", "label" : "Acme", "value" : "001R0000002GuzsIAC" }, 
      { "groupings" : [ ], "key" : "1", "label" : "Facebook", "value" : "001R0000001nUAmIAM" }, 
      { "groupings" : [ ], "key" : "2", "label" : "Home Depot", "value" : "001R0000002Gv5zIAC" }, 
      { "groupings" : [ ], "key" : "3", "label" : "Mircosoft", "value" : "001R0000002Gv5QIAS" } ]   
  },
  "hasDetailRows" : true,   
  "reportExtendedMetadata" : { 
    "aggregateColumnInfo" : {
      "s!AMOUNT" : {         
        "acrossGroupingContext" : null,         
        "dataType" : "currency",         
        "downGroupingContext" : null, 
        "label" : "Sum of Amount" },       
      "a!AMOUNT" : {         
        "acrossGroupingContext" : null,         
        "dataType" : "currency",         
        "downGroupingContext" : null,         
        "label" : "Average Amount" },       
      "RowCount" : {         
        "acrossGroupingContext" : null,         
        "dataType" : "int",         
        "downGroupingContext" : null,         
        "label" : "Record Count" }
    },     
    "detailColumnInfo" : {       
      "OPPORTUNITY_NAME" : { "dataType" : "string", "label" : "Opportunity Name" },       
      "AMOUNT" : { "dataType" : "currency", "label" : "Amount" },       
      "LEAD_SOURCE" : { "dataType" : "picklist", "label" : "Lead Source" },       
      "NEXT_STEP" : { "dataType" : "string", "label" : "Next Step" },
      "PROBABILITY" : { "dataType" : "percent", "label" : "Probability (%)" },       
      "FISCAL_QUARTER" : { "dataType" : "string", "label" : "Fiscal Period" },       
      "AGE" : { "dataType" : "int", "label" : "Age" },       
      "CREATED_DATE" : { "dataType" : "datetime", "label" : "Created Date" },       
      "FULL_NAME" : { "dataType" : "string", "label" : "Opportunity Owner" },       
      "ROLLUP_DESCRIPTION" : { "dataType" : "string", "label" : "Owner Role" }     
    },
    "groupingColumnInfo" : {       
      "ACCOUNT_NAME" : { "dataType" : "string", "groupingLevel" : 0, "label" : "Account Name" },       
      "CLOSE_DATE" : { "dataType" : "date", "groupingLevel" : 0, "label" : "Close Date" },       
      "TYPE" : { "dataType" : "picklist", "groupingLevel" : 1, "label" : "Type" }     
    }   
  },   
  "reportMetadata" : {     
    "aggregates" : [ "s!AMOUNT", "a!AMOUNT", "RowCount" ],     
    "chart" : { 
      "chartType" : "Donut",
      "groupings" : [ "CLOSE_DATE" ],       
      "hasLegend" : true,       
      "showChartValues" : false,       
      "summaries" : [ "s!AMOUNT" ],       
      "summaryAxisLocations" : [ "Y" ],
      "title" : "Pipeline by Stage and Type"
    },     
    "currency" : null,     
    "description" : null,     
    "detailColumns" : [ "OPPORTUNITY_NAME", "AMOUNT", "LEAD_SOURCE","NEXT_STEP", 
      "PROBABILITY", "FISCAL_QUARTER", "AGE", "CREATED_DATE", "FULL_NAME", "ROLLUP_DESCRIPTION" ],  
    "developerName" : "Deals_Closing_This_Quarter",
    "division" : null,     
    "folderId" : "00lR0000000M8IiIAK",     
    "groupingsAcross" : [ 
      { "dateGranularity" : "Month", "name" : "CLOSE_DATE", "sortAggregate" : null, "sortOrder" : "Asc"}, 
      { "dateGranularity" : "None", "name" : "TYPE", "sortAggregate" : null, "sortOrder" : "Asc" } ],
    "groupingsDown" : [ 
      { "dateGranularity" : "None", "name" : "ACCOUNT_NAME", "sortAggregate" : null, "sortOrder" : "Asc" } ],
    "hasDetailRows" : true,     
    "hasRecordCount" : true,     
    "historicalSnapshotDates" : [ ],     
    "id" : "00OR0000000K2UeMAK",     
    "name" : "Deals Closing This Quarter",
    "reportBooleanFilter" : null,     
    "reportFilters" : [ 
      { "column" : "BucketField_36625466", "isRunPageEditable" : true, "operator" : "equals", "value" : "Early,Late" }, 
      { "column" : "TYPE", "isRunPageEditable" : true, "operator" : "equals", "value" : "Existing Business,New Business" } ],     
    "reportFormat" : "MATRIX",     
    "reportType" : { "label" : "Opportunities", "type" : "Opportunity" },     
    "scope" : "organization",
    "showGrandTotal" : true,
    "showSubtotals" : true,
    "sortBy" : [ ],
    "standardDateFilter" : { 
      "column" : "CLOSE_DATE", 
      "durationValue" : "THIS_FISCAL_QUARTER", 
      "endDate" : "2015-09-30", 
      "startDate" : "2015-07-01" },     
    "standardFilters" : [ 
      { "name" : "open", "value" : "all" }, 
      { "name" : "probability", "value" : ">0" } ]   
  }
}

You'd need to get a list of reports. /services/data/v35.0/analytics/reports gets the 5 most recently viewed. Or ya know, you just use SOQL to get all reports you want.

NOTE:

  • Use the latest API version possible
  • According to the limits, only 500 synchronous calls per hour per instance. That may be fine for your project. Just calling it out there. I'm not putting down the async version in this answer since its a bunch of steps.

Upvotes: 1

Related Questions