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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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; }}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0