Last active
December 16, 2015 23:09
-
-
Save tyoshikawa1106/5511623 to your computer and use it in GitHub Desktop.
Visualforce CSV Download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="CsvListSearchController" cache="true" contentType="text/csv#filename.csv" language="en-US"> | |
"Name","AccountNumber","Site","NumberOfEmployees" | |
<apex:repeat value="{!accounts}" var="item"> | |
"{!item.Name}","{!item.AccountNumber}","{!item.Site}","{!item.NumberOfEmployees}" | |
</apex:repeat> | |
</apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class CsvListSearchController { | |
public List<Account> accounts {get; set;} | |
public CsvListSearchController() { | |
this.accounts = new List<Account>(); | |
} | |
public void doSearch() { | |
this.accounts = [select Id,Name,AccountNumber,Site,NumberOfEmployees from Account limit 200]; | |
} | |
public PageReference doClick() { | |
return Page.CsvListDownloadPage.setRedirect(false); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="CsvListSearchController" title="CsvListSearchPage" showHeader="true" sidebar="false" id="page"> | |
<apex:form id="form"> | |
<apex:pageBlock id="block"> | |
<apex:pageBlockButtons > | |
<apex:commandButton value=" Search!! " title=" Search!! " action="{!doSearch}" reRender="form" /> | |
<apex:commandButton value=" Download!! " title=" Download!! " action="{!doClick}" rendered="{!accounts.size > 0}" /> | |
</apex:pageBlockButtons> | |
<apex:pageBlockTable value="{!accounts}" var="item"> | |
<apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}"> | |
<apex:outputText value="{!item.Name}" /> | |
</apex:column> | |
<apex:column headerValue="{!$ObjectType.Account.Fields.AccountNumber.Label}"> | |
<apex:outputText value="{!item.AccountNumber}" /> | |
</apex:column> | |
<apex:column headerValue="{!$ObjectType.Account.Fields.Site.Label}"> | |
<apex:outputText value="{!item.Site}" /> | |
</apex:column> | |
<apex:column headerValue="{!$ObjectType.Account.Fields.NumberOfEmployees.Label}"> | |
<apex:outputText value="{!item.NumberOfEmployees}" /> | |
</apex:column> | |
</apex:pageBlockTable> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment