+ Start a Discussion

Code for a Custom Button in an Opportunity to export data in fields



I'm new to Apex coding and was wondering how a VF page would look for creating a button that would export data in an opportunity.   I'm trying to give my users the ability to hit the button in an opportunity and export company name, address, sales order # into a Network Access Database or an Excel Spreadsheet.  We'll use this database to create call tags via UPS to return an order (completed Opportunity). 




I've done this exact thing in the past. What I did was to set up a separate Visualforce page that just had one field in it, which my custom controller filled with the CSV data I needed. When the user clicks that button, they're prompted to download the file. Here's my basic code:



<apex:page standardController="Opportunity" 


 Then you just need to come up with the filename and a string consisting of your CSV data for CSVLines. See what you get to from there.







Thanks for the help.  As far as a custom controller, is this an S-Control.   And if I create headers in the the CSV file, how do I put the headers into a string on the apex code you provided?  Sorry, still a newbie.

Imran MohammedImran Mohammed

It should be a visualforce page.

Just use that tag and {!CSVLines} should be variable in your controller.

If you need an example, let me know.


Thank for the reply, yeah, would you have an example of lets just say how you would link the "Company Name" and "Phone Number" in a Salesforce Opp Page (on a Visualforce page) to a spreadsheet outside of Salesforce.  Appreciate it.