Apex:使用VF自带标签实现简单数据分页功能

本文介绍如何在Salesforce Visualforce页面上利用Apex控制器实现数据分页,展示大量Accounts信息,并提供编辑、删除功能。通过ApexPages.StandardSetController、PageReference和URLFOR等关键组件实现。
摘要由CSDN通过智能技术生成

当你想要在VF页面上展示1000+的数据时,你就必须使用分页,否则就会报错“Collection size xxxx exceeds maximum size of 1000”。本文将教你如何使用VF自带标签实现最基本的分页功能。

一、需求阐述

自定义页面,展示系统中所有accounts的名称、类型和电话,点击名称可以进入某个account的详细页面;并且在该自定义页面中,可以编辑和删除account。

二、逻辑梳理

这个需求里并没有复杂的逻辑,实现起来也非常简单,下面直接上代码>-<

三、代码实现
1. Controller
public with sharing class SepPageCtl2 {
    List<Account> accounts {get; set;}

    public SepPageCtl2 (ApexPages.StandardController controller){

    }

    //instantiate the StandardSetController from a query locator
    public ApexPages.StandardSetController con {
        get{
            if(con == null){
                con = new ApexPages.StandardSetController(Database.getQueryLocator(
                [SELECT Id, Name, Phone, Type, Industry, Owner.Name FROM Account ORDER BY Name LIMIT 100]));
                // sets the number of records in each page set
                con.setPageSize(5);
            }
            return con;
        }
        set;
    }

    // returns a list of account in the current page set
    public List<Account> getAccounts(){
        return (List<Account>) con.getRecords();
    }

    public PageReference process(){
        return null;
    }

    // indicates whether there are more records after the current page set.
    public Boolean hasNext{
        get{
            return con.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious{
        get{
            return con.getHasPrevious();
        }
        set;
    }

    // returns the page number of the current page set
    public Integer pageNumber{
        get{
            return con.getPageNumber();
        }
        set;
    }

    // returns the first page of records
    public void first(){
        con.first();
    }

    // returns the last page of records
    public void last(){
        con.last();
    }

    // returns the previous page of records
    public void previous(){
        con.previous();
    }

    // returns the next page of records
    public void next(){
        con.next();
    }

    // returns the PageReference of the original page, if known, or the home page.
    public void cancel(){
        con.cancel();
    }
}
2. VF Page
<apex:page id="SepPageDemo2" standardController=
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值