使用【getSelected()】方法可以取得选择的record的数据
1.使用【getRecords()】方法可以取得listview上边所有数据
下边修改Apex类,试试效果。
ListViewButtonDemo.cls
public class ListViewButtonDemo {
public List<Account> accounts{get;private set;}
public ListViewButtonDemo(ApexPages.StandardSetController stdSetController){
//accounts = (List<Account>) stdSetController.getSelected();
accounts = (List<Account>) stdSetController.getRecords();
}
public PageReference save(){
try{
update accounts;
} catch(Exception e){
System.debug('Exception: ' + e);
}
return null;
}
}
根据上边测试结果,当listview上边有4条数据时,可以正常显示,下边测试一下当数据超过20件时,能不能正常显示出来。
看下边显示结果,只能表示20件,原因是默认的PageSize是20,在不翻页的情况下,只能显示第一页的数据。
2.使用【getHasNext()】和【setpageNumber()】方法进行翻页取得全部数据
ListViewButtonDemo.cls
public class ListViewButtonDemo {
public List<Account> accounts{get;private set;}
public ListViewButtonDemo(ApexPages.StandardSetController stdSetController){
//accounts = (List<Account>) stdSetController.getSelected();
//accounts = (List<Account>) stdSetController.getRecords();
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;
}
public PageReference save(){
try{
update accounts;
} catch(Exception e){
System.debug('Exception: ' + e);
}
return null;
}
}
效果展示
Logs
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。