Prepare a package XML to retrieve all Report using Apex and Workbench

Prepare a package.xml file and download it

Run below code in Execute Anonymous Window using Developer Console. It will send package.xml file in your email. Don’t forget to update your email address in below code.

 String packageg = '<?xml version="1.0" encoding="UTF-8"?><Package xmlns="http://soap.sforce.com/2006/04/metadata"><types>';
 Map<String, String> folderinfo = new Map<String, String>();
 for(Folder rp: [select Name, developername from Folder where type='Report']){
    folderinfo.put(rp.name, rp.developername);
 }
 for(Report rp: [select id, FolderName, name, developername, description from report where NamespacePrefix = null]){
     if(folderinfo.containsKey(rp.FolderName)){
        packageg +='<members>'+folderinfo.get(rp.FolderName)+'/'+ rp.developername+'</members>';
     }
 }
 packageg += '<name>Report</name>';
 packageg += '</types><version>48.0</version></Package>';
 Messaging.EmailFileAttachment csvAttcmnt = new Messaging.EmailFileAttachment ();
 blob csvBlob = Blob.valueOf (packageg);
 string csvname = 'Package.XML';
 csvAttcmnt.setFileName(csvname); 
 csvAttcmnt.setBody (csvBlob);
 Messaging.SingleEmailMessage singEmail = new Messaging.SingleEmailMessage ();
 String [] toAddresses = new list<string> {'ayub.a@grazitti.com'};
 singEmail.setToAddresses (toAddresses);
 String subject ='Report Pull- Package.xml';
 singEmail.setSubject (subject);
 singEmail.setPlainTextBody ('Package XML for report');
 singEmail.setFileAttachments (new Messaging.EmailFileAttachment []{csvAttcmnt});
 Messaging.SendEmailResult [] r = Messaging.sendEmail (new Messaging.SingleEmailMessage [] {singEmail})

Retrieve Reports using Package.xml

Now, you login in org using workbench and retrieve all Reports using above received package.xml.

Or you can use the VS Code editor to retrieve the metadata by using this package.xml file.

Is it not easy to pull all reports!!

15 thoughts on “Prepare a package XML to retrieve all Report using Apex and Workbench”

  1. Hey this is kinda of off topic but I was wanting to know if blogs use WYSIWYG
    editors or if you have to manually code with HTML. I’m starting
    a blog soon but have no coding knowledge so
    I wanted to get advice from someone with experience.
    Any help would be greatly appreciated! games ps4 allenferguson games ps4

  2. Thanks , I’ve just been searching for information about this topic for ages and yours is the greatest I have came upon till
    now. However, what about the bottom line? Are you positive concerning the source?
    games ps4 185413490784 games ps4

  3. I’ve been surfing online more than three hours these
    days, but I never discovered any attention-grabbing article like yours.
    It’s pretty value sufficient for me. In my opinion, if
    all web owners and bloggers made excellent content material as you
    probably did, the net might be a lot more useful than ever
    before.

  4. I’m not that much of a online reader to be honest but your sites really nice, keep it
    up! I’ll go ahead and bookmark your website to come back
    later on. Many thanks

  5. No matter if some one searches for his essential thing,
    so he/she wants to be available that in detail, therefore that thing is
    maintained over here.

  6. Every weekend i used to visit this website, for the reason that i wish for enjoyment,
    as this this web site conations genuinely fastidious funny material too.

  7. Hello I am so happy I found your blog page, I really
    found you by mistake, while I was searching on Bing for something else, Nonetheless I am here now and would just like
    to say thank you for a tremendous post and a all round exciting blog (I also love the theme/design), I don’t have time to look over it all at the
    moment but I have bookmarked it and also included your
    RSS feeds, so when I have time I will be back to read much more,
    Please do keep up the awesome b.

Comments are closed.