Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
add comment

1 Answer 1

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}"/>
</apex:form>
</apex:page>

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


/*****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
add comment

Your Answer

 
discard

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.