前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Salesforce VisualforcePage取得标准ListView的值(二)

Salesforce VisualforcePage取得标准ListView的值(二)

原创
作者头像
repick
发布2023-03-21 10:43:33
4290
发布2023-03-21 10:43:33
举报
文章被收录于专栏:SalesforceSalesforce

使用【getSelected()】方法可以取得选择的record的数据

1.使用【getRecords()】方法可以取得listview上边所有数据

下边修改Apex类,试试效果。

ListViewButtonDemo.cls

代码语言:javascript
复制
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

代码语言:javascript
复制
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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档