Pages

Friday, March 29, 2019

Salesforce: Finding Reports and Dashboards from Private folder

Use case: unable to delete report because it used in dashboards.

When you try to delete the report, Salesforce returns the following error:

Report cannot be deleted
One or more dashboards depend on this report. Please delete the dashboard components referring to this report and try again. 

The issue is, it does not tell us which dashboard content report that we want to delete.

So, let us find the related dashboards.

1. Create Report Type 
Reports (A) with at least one related record from Dashboard Components (B)
You can add Dashboard information to this report, such as:
- Dashboard ID
- Dashboard Running User (run as specified user, or let authorized users change running user)
- Folder
- Running User (this is viewing user name)
- Running User Active
- Title

You may find in some of the reports, there is no Dashboard info, even the report type is Reports with at least one related record from Dashboard Components, this is pretty confusing, right?

Possibility (1)
The dashboard has been deleted, you are right, however, once the dashboard is deleted (in recycle bin), the system allows you to delete the report.


 If you see from the above screenshot, the first line does not have dashboard info, this because the dashboard is deleted, and system allows me to delete the report, so this does not fit our use case.

Possibility (2)
The dashboard is stored in someone Private folder.


The difference here, we can see dashboard Title and no other info. For this case, we cannot delete the report.




2. Query from Private folders
For reports used as the source of dashboards that are stored in someone's private dashboard, you need to query from the Private folder. You need to have this permission of "Manage All Private Reports and Dashboards", so you can query the dashboard and report stored in the Private folder. You also need to add  'allPrivate' query scope to find Reports and Dashboards in private folders.

To return reports in private folders that haven't been run for more than one year:
SELECT Id, OwnerId FROM Report USING SCOPE allPrivate WHERE LastRunDate < LAST_N_DAYS:365

To query reports inside a specific User's private folder:
SELECT Id FROM Report USING SCOPE allPrivate WHERE OwnerId = '005A0000000Bc2deFG'

To query all dashboards stored in the User's private folder:
SELECT Id, Title, FolderName, FolderId, CreatedById, LastModifiedById FROM Dashboard USING SCOPE allPrivate ORDER BY Title 



Note:
For Dashboard:
- You should look at FolderId - this is where the dashboard or report is stored.
- The dashboard or report can be created by someone else, so don't look at CreatedById.

For Report:
- Look for OwnerId; this will tell you who owned the report stored in the private folder.


First Query
SELECT Id, DeveloperName, OwnerId, CreatedById, Owner.Name, CreatedBy.Name, CreatedBy.IsActive, Name, LastRunDate FROM Report USING SCOPE allPrivate
This query will return all reports stored in all user's private folders.

Second Query
SELECT Id, DeveloperName, OwnerId, CreatedById, Owner.Name, CreatedBy.Name, CreatedBy.IsActive, NameLastRunDate FROM Report
This query will return all reports in your private folder, public folders, and all custom folders.

So, if you combine the results of the above query, you will get duplicate results for reports that sit in your private folder, so you can exclude those reports from the second query, such as
SELECT Id, DeveloperName, OwnerId, CreatedById, Owner.Name, CreatedBy.Name, CreatedBy.IsActive, Name, LastRunDate FROM Report WHERE OwnerId <> '00580000004JEgTAAW'



Reference

13 comments:

  1. Hi Johan,
    Improved my skills through your blog .
    is it possible to write Soql query to get dashboards running by inactive user?

    ReplyDelete
    Replies
    1. yes, here you go SELECT Id,RunningUserId FROM Dashboard where RunningUser.isActive = false

      Delete
  2. Hi Johan,
    Do you know if the same functionality exist on Einstein analytics ?
    I'm trying to delete a dataset but it is used in a dashboard. I can't access the dashboard (while I'm sysadmin). Therefor I would like to know if I can find the user who has this dashboard in his private folder.
    Thank you

    ReplyDelete
    Replies
    1. Hi, I remember there is a permission called 'Manage Analytics Private Assets' under EA perm set, but not sure if that work, have you try?

      Delete
    2. Same issue here.. Is there a way to query the reports/dashboards in Analytics side?
      The permission set mentioned above only works for seeing the datasets, not the dashboards.

      Delete
    3. I cant remember this, but If I am not wrong, when you try to delete a dataset, it will stop you when the dataset used in dashboard, including stored in private app

      Delete
  3. Hi, is it possible to recover a dashboard from an inactive user?

    ReplyDelete
    Replies
    1. re-enable the user temporary, login as that user, then move the dashboard to public folder

      Delete
  4. Hi Johan,

    Is it possible to write a query to see if a report is being utilized on a dashboard? In MSSQL it would be a simple sub-select, and was wondering what the syntax would be for SOQL.

    Thanks!

    ReplyDelete
    Replies
    1. Use Rest Explorer, check out this sample https://na89.salesforce.com/sfc/p/300000000SHq/a/2J000000VaUb/MJgZkZhwkfrfp4b6EBKfZ8_3uLQ.ebVWTHLhi5Z88Tk

      Delete
  5. Hi, I need to mass delete the dashboards. Any suggestions?
    I tried to mass delete the reports which are not in use. In Setup-> mass delete reports. But my reports are used in the dashboards i cant delete. Any suggestions?

    ReplyDelete
    Replies
    1. seems like no easy way unless you use IDE tool, checkout this and feel free to vote https://trailblazer.salesforce.com/ideaView?id=08730000000DjFzAAK

      Delete
  6. Amazing content, saved me some time. Thank you!

    ReplyDelete