Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a SFDC App which does data (Account, Contact, Lead) segmentation and flags them according to segmentation rules. I want to be able to provide a link on visualforce page to download certain accounts/contacts/leads (according to flag) in csv/excel(whichever is easy to do) format. How to do it?

share|improve this question
up vote 1 down vote accepted

You can use following for your purpose

<!-- Your Main Page -->
<apex:page controller="DownloadData">
<apex:form >
<apex:commandButton value="DownloadRecords" action="{!records}"/>

<!-- -Your DownloadDemo Page- -->
<apex:page controller="DownloadData"  contentType="application/" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!data}" var="d">
<apex:column value="{!d.ID}"/>
<apex:column value="{!d.Data__c}"/>

/*****Same Controller for both the classes*****/
 public with sharing class DownloadData {

public PageReference records() 
   return new PageReference('/apex/DownloadDemo');

public List<MyObject__c> getData() {

    List<MyObject__c> mo = [SELECT ID,Data__C FROM MyObject__c];

    return mo;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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