What are the correct steps to get data back from an AppAnalyticsQueryRequest?

Salesforce documentation is really thin on this and there is lot of scope to make it clear.


1.Log a case with Salesforce support to get this feature enabled in your LMO

2.Create a permission set with access to the AppAnalyticsQueryRequest object

Here are the steps to create AppAnalyticsQueryRequest .

1.Login to the workbench from your LMO (License Management Org)

2.Navigate to data insert for the AppAnalyticsQueryRequest

enter image description here

3.Fill in the required field details

enter image description here

The key here is you will need to specify either organizationId or the packageId. Both of them cannot be null.You can obtain the packageId from your packaging org.

Also for DataType use CustomObjectUsageLog.

CAUTION: Its not CustomObjectUsageSummary, instead use "CustomObjectUsageLog"

4.Insert the data. Now use the developer console to write a simple query like below

SELECT  ID, Downloadurl, DownloadExpirationTime, StartTime FROM AppAnalyticsQueryRequest

enter image description here

NOTE - It may take somewhere between 30minutes to 1 hour before you see the download url. (execute the query after an hour or so).Once you have the download url, visit the url to download the csv and analyze the data.

Troubleshooting Tips

Now that I got it working, here are some troubleshooting lessons learned:

  1. If you don’t specify an EndTime, the StartTime must be 7 days or fewer from today to avoid a limits error.
  2. You must specify values for either PackageIds or OrganizationIds. Both can’t be wildcard/blank.
  3. Values provided to OrganizationIds or PackageIds must use the 15-digit RecordID format.
  4. You can only run so many App Analytics queries per day against the same LMO (based on your license and such)
  5. CustomObjectUsageSummary doesn't work. Use CustomObjectUsageLog instead.

To begin with, after you have AppAnalytics activated, you should create a permission set in the org where you LMO is, in order to grant you (and other users) CRUD access to the AppAnalyticsQueryRequest object.

After that, you'll be submitting a record to the AppAnalyticsQueryRequest object, which should:

  1. Specify the DataType

  2. Have a StartTime and EndTime within the range of a week (EndTime is optional)

  3. Specify OrganizationIds (or if left blank it will be wildcard and consider all of your subscriber orgs that are active)

  4. Specify PackageIds (or if left blank it will be wildcard and consider all of your packages that are actived with AppAnalytics)

We recommend submitting the request through the CLI, for example: ~codey$ sfdx force:data:record:create -s AppAnalyticsQueryRequest -v “StartTime=2019-06-08T:12:00:00 EndTime=2019-06-12T12:00:00 DataType=CustomObjectUsageLog PackageIds=0331U000000EHq2”-u CodeysPBO

As a reference, this blog post will guide you step by step on how to get started: https://medium.com/inside-the-salesforce-ecosystem/get-app-smart-how-to-use-appexchange-app-analytics-bd0751c68ca6

Please let us know if you have any questions.

The Salesforce labs team also recently launched this app which works as a UI for your AppAnalytics request and can be installed in your org with your LMO: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000G0nUXUAZ