28

I'm a huge fan of the Query Editor in the SFDC Developer Console:

screenshot of query editor with results

Is there a way to export the table of results as JSON/csv/excel or in some format that can be consumed by Excel?

(I know that I can replicate the functionality in DemandTools or other tools, but sometimes when I've thrown up a query for debugging, it would be really handy to be able to export and manipulate the results.)

  • The dev console was not built for this. You can copy your query and paste it in the Force.com data loader. Its a powerful tool. – mugume david Jun 12 '15 at 7:59
23

The Developer Workbench will allow you to, among other things, build SOQL queries and save the results as CSV: https://workbench.developerforce.com/login.php

  • Good call - I find the Developer Console quicker for quick exploration and debugging, but good to remember that I can always copy my query over to Workbench. – Benj Aug 12 '13 at 18:52
  • 3
    Sadly the Developer Workbench is restricted, when it comes down to relationship or aggregate queries. There are often times, when the Developer console is the only way to get the results. – Alexander Johannes Oct 15 '14 at 7:30
24

UPDATE
For faster use add a bookmark, pick a name and paste the following code to the URL:

javascript:(function(){function e(e){var t=new RegExp(/["]/g),n=e.replace(t,"“"),t=new RegExp(/\<[^\<]+\>/g),n=n.replace(t,"");return""==n?"":'"'+n+'"'}for(var t=document.evaluate("//div[@id='editors-body']/div[not(contains(@style,'display:none') or contains(@style,'display: none'))]//table/tbody/tr",document,null,0,null),n=[];row=t.iterateNext();){for(var o=row.getElementsByTagName("td"),a=[],r=0;r<o.length;r++)a.push(e(o[r].textContent));n.push(a)}for(var d="data:text/csv;charset=utf-8,filename=download.csv,",l=[],r=0;r<n.length;r++)l.push(n[r].join(","));d+=l.join("\r\n");var c=document.createElement("a");c.setAttribute("href",encodeURI(d)),c.setAttribute("download","dev_console.csv"),document.body.appendChild(c),c.click()})();

Save it. Now with one click it will download console results into csv file. (Tested in Chrome)

ORIGINAL ANSWER
I have a quick solution which works for me since I do a lot of exports from console. Script opens a new window with raw data in csv format and a link to a downloadable csv file. My script works in Chrome, didn't check it in other browsers.

  1. Select the tab you want to export ( script takes only active tab )
  2. Press F12 ( firebug window ) and go to console.
  3. Copy / paste the following script and press enter. Don't forget to allow to pop a window ( Chrome usually blocks it ).
  4. Enjoy..

var o = document.evaluate("//div[@id='editors-body']/div[not(contains(@style,'display:none') or contains(@style,'display: none'))]//table/tbody/tr",document,null,0,null); var r = []; while(row = o.iterateNext()){ var cols = row.getElementsByTagName('td'); var a = []; for(var i=0; i<cols.length; i++){ a.push( formatData( cols[i].textContent ) ); } r.push( a ); } // generating csv file var csv = "data:text/csv;charset=utf-8,filename=download.csv,"; var rows = []; for(var i=0; i<r.length; i++){ rows.push( r[i].join(",") ); } csv += rows.join('\r\n'); popup(csv); function formatData(input) { // replace " with “ var regexp = new RegExp(/["]/g); var output = input.replace(regexp, "“"); //HTML var regexp = new RegExp(/\<[^\<]+\>/g); var output = output.replace(regexp, ""); if (output == "") return ''; return '"' + output + '"'; } // showing data in window for copy/ paste function popup(data) { var generator = window.open('', 'csv', 'height=400,width=600'); generator.document.write('<html><head><title>CSV</title>'); generator.document.write('</head><body style="overflow: hidden;">'); generator.document.write('<a href="'+encodeURI(csv)+'" download="Sf_export.csv">Download CSV</a><br>'); generator.document.write('<textArea style="width: 100%; height: 97%;" wrap="off" >'); generator.document.write(data); generator.document.write('</textArea>'); generator.document.write('</body></html>'); generator.document.close(); return true; }
  • 2
    Works great, I might try to make this into a chrome extension. Are you cool with me using your code? – NSjonas Feb 6 '15 at 18:36
  • @NSjonas yea, absolutely, please go on :D I found another option which works great, I use a tool called aside.io, it's kind of browser IDE and they let you export any results and edit / remove query results. Worth a try! – NGix Aug 7 '15 at 13:23
  • @NSjonas I updated my answer, the easiest way is to use a bookmark, it's just one click. – NGix Dec 12 '16 at 10:35
  • @NSjonas Superuseful! Is this the one? chrome.google.com/webstore/detail/sdfc-dev-console-data-exp/… – Javier García Manzano Jul 28 '17 at 10:54
20

I have a quick and dirty solution :()

First open a console and query some records. Then open a FireBug window (F12, i hope you have it). Select the query results table with a firebug's select arrow. You need to turn off the css styles -moz-user-select: none for the <div id="gridview-1182" to be able to select the result text. Then select all results just with a mouse, copy and paste it to Excel. Works great for me!

Step 1: activate user select

enter image description here

Step 2: select results

enter image description here

Step 3: copy & paste it to excel

enter image description here

  • 2
    Just to add I just tried this with the "Overall Code Coverage" table and it works there also =] – Girbot Jun 23 '15 at 9:51
  • 2
    I like this dirty solution as I could not use workbench due to some firewall stuff. – unidha Mar 10 '16 at 3:32
1

I found a tool which I use for just exports from console. It's kind of free browser IDE called aside.io where you can actually export in csv format, bulk delete or do other things with queries.

enter image description here

For me it's much better than custom scripts. Disclaimer: I'm not associated with aside.io in any ways.

1

I see a few others have mentioned external tools. I help make the FuseIT SFDC Explorer, which is free from my current employer.

With it you can export the results to CSV or directly to the clipboard.

enter image description here

1

Here is a simple way:

  1. Run your query in query builder.
  2. Hit F-12 and click on any row of the query builder's result.
  3. In developer console switch from tr to table.
  4. Copy table's html and paste into notepad.
  5. save notepad as html and open it in a browser.
  6. you can easily copy your desired rows or whole result set from here.
1

Download the SDFC Dev Console Data Exporter Chrome's extension to get the data in CSV format.

  • The link is for the chrome extension. There is not that should be copied from there! – m Peixoto Apr 5 at 12:03
0

What you are looking for is dataloader.io you can select your object, columns and make a custom select query, then export all to CSV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.