function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Wes Cooper.ax1560Wes Cooper.ax1560 

Extract SOQL as CSV

Hi - I'm a bit new to Apex programming and I have a quick question.

 

Can I export the contents of a SOQL query within an APEX Global class to a CSV file? I know that we can use the Data Tool and possibly a VF page, but my company wants this to happen automatically, without any human intervention. Is there a way to do this, and if so, does anyone have a link that I can use as a guide?

 

Thanks for your time,

 

Wes Cooper

Raj.ax1558Raj.ax1558

You need firstly create list of records, then list is bind with visualforce page. Write this code on visualforce page.

<apex:page controller="xyz"  contentType="application/csv#dispositionSummaryReport.csv" showHeader="false" cache="false">

Column1,Column2,Column3
<apex:repeat value="{!recordlist}" var="rec">
{!rep.ReportCol1},{!rec.columnn1},{!rec.column2},{!rec.column3}
</apex:repeat>

</apex:page>
               

Please mark this as solution for others to get it easily
Rasmitha ReddyRasmitha Reddy

Hi

 

what iam understanding you mean to say is can we export the data automatically by using data tool(dataloader)?

 

yes we can export the data automatically  with out manually through dataloader by using comand line interface(CLI)

Please go through the following wiki page. This has the step by step instructions to execute a job using the Data Loader CLI.

 

http://wiki.developerforce.com/page/Using_Data_Loader_from_the_command_line