Sub topic 13
Auditing dashboards with SOQL
This chapter assumes you can write basic SOQL (Salesforce Object Query Language), you know what a running user is, and you have read the chapters on dynamic dashboards and edition limits. You will query the Dashboard object to see which running-user types your org uses.
Why audit with SOQL
The Dashboards tab shows one folder at a time. It cannot tell you how many dashboards run as a fixed user and how many run as the logged-in user. A query can answer that in seconds. You can run it in the Developer Console Query Editor or in Salesforce CLI.
Two audit questions come up most often:
- Which dashboards are dynamic, so each viewer sees their own data?
- How close is the org to its dynamic dashboard limit?
The Dashboard object
Each dashboard is a record on the Dashboard object. These fields matter for an audit:
| Field | Meaning |
|---|---|
| `Title` | The name people see |
| `DeveloperName` | The unique API name |
| `FolderName` | The folder that holds the dashboard |
| `Type` | The running-user type |
| `RunningUserId` | The user whose access defines the data |
Type has three values you will meet: SpecifiedUser (a fixed running user), LoggedInUser (a dynamic dashboard) and MyTeamUser (the viewer's manager sees each direct report's data). The values can vary by org and API version, so check the field's picklist values in your org before you rely on them.
List the dynamic dashboards
Filter on Type = 'LoggedInUser':
SELECT Id, Title, DeveloperName, FolderName, Type, RunningUserId
FROM Dashboard
WHERE Type = 'LoggedInUser'Each row is a dynamic dashboard. Use the result to review who owns them and which folders they sit in. A dynamic dashboard shows each viewer their own data, so a folder shared with a wide audience makes sense here. Check that the folder is not shared more widely than it should be.
Count dashboards by type
Group by Type to see the mix:
SELECT Type, COUNT(Id) total
FROM Dashboard
GROUP BY TypeThe LoggedInUser count is the number to compare against your edition's limit on dynamic dashboards. The limit differs by edition, so read the current figure in Salesforce Help instead of relying on a number from memory.
Reading the results
- A high
SpecifiedUsercount. Many dashboards show the running user's view to everyone. If that user can see more than viewers should, you have a data visibility risk. Check these first. - A
LoggedInUsercount near the limit. You cannot create more dynamic dashboards. Retire unused ones or combine them before a team needs a new one. - A
RunningUserIdthat points to a deactivated user. The dashboard may show empty or stale components. Reassign the running user.
Aggregate queries have limits
The Dashboard object works best for definitions, not the data inside the dashboard. A query tells you how a dashboard is set up. It does not tell you what numbers it shows. For the numbers, open the dashboard or the source report.
Some fields on Dashboard may not be queryable in every API version. If a query returns an error about a field, remove that field and run it again.
Exercise
Exercise
Write a SOQL query that counts dashboards by running-user type, then say which result you would compare with the edition limit on dynamic dashboards.
Show answer
SELECT Type, COUNT(Id) total FROM Dashboard GROUP BY Type. Compare the count in the row where Type is LoggedInUser, because those are the dynamic dashboards.
Exercise
A query for Type = 'SpecifiedUser' returns a dashboard whose RunningUserId belongs to a deactivated user. What problem can this cause, and what is the fix?
Show answer
Components can show empty or stale data because the running user no longer has valid access. Edit the dashboard and set an active running user, or convert it to a dynamic dashboard if each viewer should see their own data.