You need to sign in to do that
Don't have an account?
udayar_jayam
Downloading Custom object records to text file with fixed width format using Apex and VF
Hi All,
I trying to download program for custom object , we the user click the "Download" custom button it should download all the records from the custom object. This download file should in text format(.txt) with fixed width. Kindly anyone tell ideas and links for this. Thanks in advance
Hi,
You can create a text file by following way (I am doing this stuff on Account object, you can use for your object) -
1. Create visualforce page with standard controller = Account (choose on which object you want Download button)
Name of VF page : DownloadAccount:-
<apex:page contentType="text/plain/#account.txt" cache="false" standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
<apex:repeat var="a" value="{!accounts}">
{!a.name}
</apex:repeat>
</apex:page>
2. Create a custom button for listl page name Download-
1.1 Goto setup-->Account--> Button and Links--> New Button--> Display Type = List Button and Content Source = visualforce page(DownloadAccount)
3. Go to search layout and set visible to this Download button on list view page of Account.
4. On Account Detail Page create a view and select it. This view will act as filter to retrieve the record in text file. If selected view have 0 records then text file have also 0 records, so use View carefully.
Click on Download button, it will automatically download your all records in account.text file
/**if this post helps you, please throw a kudos by clicking star**/
Thanks
www.grazitti.com
All Answers
Hi,
You can create a text file by following way (I am doing this stuff on Account object, you can use for your object) -
1. Create visualforce page with standard controller = Account (choose on which object you want Download button)
Name of VF page : DownloadAccount:-
<apex:page contentType="text/plain/#account.txt" cache="false" standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
<apex:repeat var="a" value="{!accounts}">
{!a.name}
</apex:repeat>
</apex:page>
2. Create a custom button for listl page name Download-
1.1 Goto setup-->Account--> Button and Links--> New Button--> Display Type = List Button and Content Source = visualforce page(DownloadAccount)
3. Go to search layout and set visible to this Download button on list view page of Account.
4. On Account Detail Page create a view and select it. This view will act as filter to retrieve the record in text file. If selected view have 0 records then text file have also 0 records, so use View carefully.
Click on Download button, it will automatically download your all records in account.text file
/**if this post helps you, please throw a kudos by clicking star**/
Thanks
www.grazitti.com
Hi Grazitti ,
Thanks for your help,I have one more issues how can i add break line in this code.which make the changes notepad text file.