Guest User

Untitled

a guest
Jul 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //First query all DashboardDolder in the org.
  2. Map<Id,Folder> folderMap = new Map<Id,Folder>([SELECT Id,
  3. DeveloperName,
  4. NameSpacePrefix
  5. FROM Folder
  6. WHERE
  7. Type = 'Dashboard']);
  8.  
  9. //Query all Dashboards in the system.
  10. List<Dashboard> dashboardList = [SELECT FolderId,
  11. DeveloperName,
  12. NameSpacePrefix
  13. FROM Dashboard
  14. USING SCOPE everything];
  15.  
  16. List<String> DashboardNames = new List<String>();
  17.  
  18. for(Dashboard DashboardObj: dashboardList){
  19. String DashboardName;
  20. //If a Dashboard is inside the folder then we should get the folder name also.
  21. //If Dashboard is in public folders then we should prefix with "unfiled$public"
  22. //We should also check for Managed package Dashboards. If namspace is not blank then prepend foldername and dashboardname followed
  23. //by '__'
  24.  
  25. if(folderMap.containsKey(DashboardObj.FolderId)){
  26. if(String.isNotBlank(folderMap.get(DashboardObj.FolderId).NameSpacePrefix)){
  27. DashboardName = folderMap.get(DashboardObj.FolderId).NameSpacePrefix + '__' + folderMap.get(DashboardObj.FolderId).DeveloperName;
  28. }else{
  29. DashboardName = folderMap.get(DashboardObj.FolderId).DeveloperName;
  30. }
  31.  
  32. if(String.isNotBlank(DashboardObj.NameSpacePrefix)){
  33. DashboardName = DashboardName + '/' + DashboardObj.NameSpacePrefix + '__' + DashboardObj.DeveloperName;
  34. }else{
  35. DashboardName = DashboardName + '/' + DashboardObj.DeveloperName;
  36. }
  37.  
  38. DashboardNames.add(DashboardName);
  39. }else{
  40. if(String.isNotBlank(DashboardObj.NameSpacePrefix)){
  41. DashboardName = 'unfiled$public/' + DashboardObj.NameSpacePrefix + '__' + DashboardObj.DeveloperName;
  42. }else{
  43. DashboardName = 'unfiled$public/' + DashboardObj.DeveloperName;
  44. }
  45.  
  46. DashboardNames.add(DashboardName);
  47. }
  48.  
  49. }
  50.  
  51. System.debug(JSON.serialize(DashboardNames));
  52. //Once all Dashboard names are printed, we can prepare package file and retrieve Dashboards from Org.
Add Comment
Please, Sign In to add comment