Salesforce: using custom query widgets

In Salesforce, objects (tables) and records are mapped to database tables and rows, and any object can be queried in a variety of different ways using a SQL-like database query language known as SOQL.

AppInsights supports 4 types of query based metrics that can fill in most of our visualizations between them. You can find them under the Salesforce button among the other metrics. They all start with the word "custom". Once they are set, each will
 run their queries once every 10 minutes and the data will automatically update on your dashboard.
Salesforce Queries

Custom Count

The custom count widget is the simplest of the query metrics, as it just executes a count of whatever you specify.

Example - How many contacts have account names that starts with United Oil:
 

SELECT Count() from Contact WHERE Account.Name LIKE 'United Oil%'
 
In order to use our Custom Count query, just select Contact from the Table dropdown, then type in Account.Name LIKE 'United Oil%' inside the WHERE field. 
Custom Count

Custom Numerical Query

The custom numerical query widget allows you to create number based widgets like dials and line graphs.

Example -  sum up the "Amount" of all your Opportunities who's name started with the letter G:

SELECT Sum(Amount) FROM Opportunity WHERE Name LIKE 'G%'
 
To put this query into our number query widget, you would first select the name of the table (Opportunity, in this case). Then you would place Sum(Amount) under the SELECT field, and Name LIKE 'G%' under the WHERE field, then you can click Save. 
Custom Numeric Query

Custom Leaderboard Query

The custom leaderboard query allows you to show name-value data on our Leaderboards, Pie Charts, and Bar Graphs.

Example - which lead sources were giving you the best opportunities:

SELECT LeadSource, Sum(Amount) FROM Opportunity GROUP BY LeadSource
This will give you a leaderboard with all of your lead sources, sorted by how much of your total opportunity amounts they contributed to. To put this query into our custom leaderboard query widget, you would select the name of the table (Opportunity, in this case). Then place LeadSource in the first SELECT box (Column 1), and Sum(Amount) in the second SELECT box (Column 2). You would also place LeadSource under the GROUP BY box. NOTE: the second SELECT box should consist of numerical data in order for our widgets to properly display any results.
Custom Leaderboard Query


​Custom Table Query

The custom table query widget simply outputs tabular data.

Example - build a table of the first name and the account name of all contacts:
 
SELECT Contact.FirstName, Contact.Account.Name FROM Contact
 
This would translate into the following in our table widget. You would select Contact from the Table dropdown, and type in Contact.FirstName, Contact.Account.Name into the SELECT box.
Custom Table Query

Additional Resources

Here is a list of the objects (tables) and field names that come with Salesforce by default. ​However, your company may have added custom tables and fields as well. For these, ask a Saleforce admin what the API name is for the field. These custom API names will always have two underscores and a lowercase "c" at the end  (ie: "custom_emails__c").

Was this tutorial helpful?  Please take a moment to submit your “Yes” or “No” answer below!  You can also contact us or post a public question for further instruction.

Did you find this article helpful?