关于取得标准ListView数据的方法前边已经讲过了,下边使用VisualforcePage看如何生成CSV文件。
1.Apex类跟之前一样,使用【getRecords】方法取得所有标准listview的数据。
ListViewDownloadController.cls
public with sharing class ListViewDownloadController {
public List<Account> accounts{get;private set;}
public ListViewDownloadController(ApexPages.StandardSetController stdSetController){
List<Account> accs = new List<Account>();
Integer count = 0;
do {
count++;
stdSetController.setpageNumber(count);
system.debug('>>>>>>>>>>>>>>getPageNumber()>>>>>>>>>>>>>>>>>>>' + stdSetController.getPageNumber());
for (Account acc : (List<Account>) stdSetController.getRecords()) {
accs.add(acc);
system.debug('>>>>>>>acc.Id>>>acc.Name>>>>>>>>>>>>>>>>>>>' + count + '>>>>>>' + acc.Id + '>>>'+ acc.Name);
}
system.debug('>>>>>>>>>>>>>>accs>>>>>>>>>>>>>>>>>>>'+accs.size());
system.debug('>>>>>>>>>>>>>>getHasNext>>>>>>>>>>>>>>>>>>>'+stdSetController.getHasNext());
system.debug('>>>>>>>>>>>>>>getPageSize()>>>>>>>>>>>>>>>>>>>'+stdSetController.getPageSize());
} while (stdSetController.getHasNext());
accounts = accs;
}
}
2.VisualforcePage做成
getAccountListDownloadForVf.page
<apex:page standardController="Account" recordSetVar="accounts" extensions="ListViewDownloadController"
cache="true" contentType="text/csv;charset=Shift_JIS;#exportAccountList.csv">
"Name","従業員数","業種","説明"
<apex:repeat value="{!accounts}" var="item">
"{!item.Name}","{!item.NumberOfEmployees}","{!item.Industry}","{!item.Description}"
</apex:repeat>
</apex:page>
getAccountListDownloadForVf.page-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>56.0</apiVersion>
<availableInTouch>false</availableInTouch>
<confirmationTokenRequired>false</confirmationTokenRequired>
<label>getAccountListDownloadForVf</label>
</ApexPage>
3.Listbutton做成
4.效果展示
exportAccountList.csv
5.关于制限
当做成1000件数据时,可以正常做成CSV文件
当做成1001件数据时,跟之前一样,不能正常生成csv文件。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。