Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //First query all DashboardDolder in the org.
- Map<Id,Folder> folderMap = new Map<Id,Folder>([SELECT Id,
- DeveloperName,
- NameSpacePrefix
- FROM Folder
- WHERE
- Type = 'Dashboard']);
- //Query all Dashboards in the system.
- List<Dashboard> dashboardList = [SELECT FolderId,
- DeveloperName,
- NameSpacePrefix
- FROM Dashboard
- USING SCOPE everything];
- List<String> DashboardNames = new List<String>();
- for(Dashboard DashboardObj: dashboardList){
- String DashboardName;
- //If a Dashboard is inside the folder then we should get the folder name also.
- //If Dashboard is in public folders then we should prefix with "unfiled$public"
- //We should also check for Managed package Dashboards. If namspace is not blank then prepend foldername and dashboardname followed
- //by '__'
- if(folderMap.containsKey(DashboardObj.FolderId)){
- if(String.isNotBlank(folderMap.get(DashboardObj.FolderId).NameSpacePrefix)){
- DashboardName = folderMap.get(DashboardObj.FolderId).NameSpacePrefix + '__' + folderMap.get(DashboardObj.FolderId).DeveloperName;
- }else{
- DashboardName = folderMap.get(DashboardObj.FolderId).DeveloperName;
- }
- if(String.isNotBlank(DashboardObj.NameSpacePrefix)){
- DashboardName = DashboardName + '/' + DashboardObj.NameSpacePrefix + '__' + DashboardObj.DeveloperName;
- }else{
- DashboardName = DashboardName + '/' + DashboardObj.DeveloperName;
- }
- DashboardNames.add(DashboardName);
- }else{
- if(String.isNotBlank(DashboardObj.NameSpacePrefix)){
- DashboardName = 'unfiled$public/' + DashboardObj.NameSpacePrefix + '__' + DashboardObj.DeveloperName;
- }else{
- DashboardName = 'unfiled$public/' + DashboardObj.DeveloperName;
- }
- DashboardNames.add(DashboardName);
- }
- }
- System.debug(JSON.serialize(DashboardNames));
- //Once all Dashboard names are printed, we can prepare package file and retrieve Dashboards from Org.
Add Comment
Please, Sign In to add comment