Salesforce 获取记录状态计数的更有效方法

Salesforce 获取记录状态计数的更有效方法,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我有一个使用standardSetController分页的visualforce页面。在页面上,我还添加了按状态过滤…即。新建、正在工作、已关闭等。现在,我正在对每个状态值执行count(),以在页面上显示状态计数,但这需要对每个状态进行查询,效率低下。我想以一种更有效的方式获得状态计数 <div class="contact-form"> <apex:outputPanel id="contactF

我有一个使用standardSetController分页的visualforce页面。在页面上,我还添加了按状态过滤…即。新建、正在工作、已关闭等。现在,我正在对每个状态值执行count(),以在页面上显示状态计数,但这需要对每个状态进行查询,效率低下。我想以一种更有效的方式获得状态计数

                <div class="contact-form">


                    <apex:outputPanel id="contactForm">
                        <apex:form >
                            <ul class="filteredView">
                                <li>
                                    <apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
                                </li>
                                <li>
                                    ({!NewStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
                                        <apex:param name="myParam" value="New"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!WorkingStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
                                        <apex:param name="myParam" value="Working"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ResolvedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
                                        <apex:param name="myParam" value="Resolved"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ClosedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
                                        <apex:param name="myParam" value="Closed"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!CancelledStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
                                        <apex:param name="myParam" value="Cancelled"/>
                                    </apex:commandLink>
                                </li>
                                <li id="last">
                                    ({!ReopenedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
                                        <apex:param name="myParam" value="Reopened"/>
                                    </apex:commandLink>
                                </li>
                            </ul>
                            <h5>
                                TICKETS
                            </h5> 
                            <table width="95%" border="1" cellpadding="5">
                                <tr align="left">
                                    <th style="width:25px;">Ticket#</th>
                                    <th style="width:200px;">Subject</th>
                                    <th>Description</th>
                                    <th style="width:50px;">Status</th>
                                    <th style="width:75px;"></th>
                                </tr>
                                <apex:repeat value="{!tickets}" var="ticket">
                                    <tr>
                                        <td>{!ticket.Ticket_Number__c}</td>
                                        <td>{!ticket.Name}</td>
                                        <td>{!ticket.Description__c}</td>
                                        <td>{!ticket.Status__c}</td>
                                        <td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
                                <ul>
                                    <li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
                                    <li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
                                    <li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
                                </ul>
                            </apex:outputPanel>
                        </apex:form>
                    </apex:outputPanel>                     
                </div>
        </div>
这是我的控制器:

public with sharing class myController {

public ApexPages.StandardSetController setCtrl{get; set;}
public String projId { get; set; }
public String clientName { get; set; }
private List<Ticket__c> TicketList = new List<Ticket__c>();

public myController()
{
    projId = ApexPages.currentPage().getParameters().get('id');
    clientName = [Select Client__r.Name From Project__c Where Id =: projId].Client__r.Name;
    setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId ORDER BY CreatedDate DESC]));
    ticketList = (List<Ticket__c>)setCtrl.getRecords();
    setCtrl.setPageSize(5);
}

public Integer getNewStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'New'];
}

public Integer getWorkingStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Working'];
}

public Integer getResolvedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Resolved'];
}

public Integer getClosedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Closed'];
}

public Integer getCancelledStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Cancelled'];
}

public Integer getReopenedStatusCount() {
    return [select count() from Ticket__c Where Project__c =: projId and status__c = 'Reopened'];
}

public Boolean hasNext {
    get {
        return setCtrl.getHasNext();
    }
}

public Boolean hasPrevious {
    get {
        return setCtrl.getHasPrevious();
    }
    set;
}

public Integer pageNumber {
    get {
        return setCtrl.getPageNumber();
    }
    set;
}

public Integer totalPages {
    get {
        totalPages = math.ceil((Double)setCtrl.getResultSize() / setCtrl.getPageSize()).intValue();
        return totalPages;
    }
    set;
}

public void first() {
    setCtrl.first();
}

public void last() {
    setCtrl.last();
}

public void previous() {
    setCtrl.previous();
}

public void next() {
    setCtrl.next();
}


public List<Ticket__c> getTickets()
{
    return (List<Ticket__c>)setCtrl.getRecords();
}

public void filterStatus() {
    string myParam = apexpages.currentpage().getparameters().get('myParam');
    setCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([select Ticket_Number__c, Name, Status__c, Description__c, Description_of_Resolution__c, CreatedDate from Ticket__c Where Project__c =: projId AND Status__c =: myParam ORDER BY CreatedDate DESC]));
    setCtrl.setPageSize(5);
}
}
                <div class="contact-form">


                    <apex:outputPanel id="contactForm">
                        <apex:form >
                            <ul class="filteredView">
                                <li>
                                    <apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
                                </li>
                                <li>
                                    ({!NewStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
                                        <apex:param name="myParam" value="New"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!WorkingStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
                                        <apex:param name="myParam" value="Working"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ResolvedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
                                        <apex:param name="myParam" value="Resolved"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ClosedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
                                        <apex:param name="myParam" value="Closed"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!CancelledStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
                                        <apex:param name="myParam" value="Cancelled"/>
                                    </apex:commandLink>
                                </li>
                                <li id="last">
                                    ({!ReopenedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
                                        <apex:param name="myParam" value="Reopened"/>
                                    </apex:commandLink>
                                </li>
                            </ul>
                            <h5>
                                TICKETS
                            </h5> 
                            <table width="95%" border="1" cellpadding="5">
                                <tr align="left">
                                    <th style="width:25px;">Ticket#</th>
                                    <th style="width:200px;">Subject</th>
                                    <th>Description</th>
                                    <th style="width:50px;">Status</th>
                                    <th style="width:75px;"></th>
                                </tr>
                                <apex:repeat value="{!tickets}" var="ticket">
                                    <tr>
                                        <td>{!ticket.Ticket_Number__c}</td>
                                        <td>{!ticket.Name}</td>
                                        <td>{!ticket.Description__c}</td>
                                        <td>{!ticket.Status__c}</td>
                                        <td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
                                <ul>
                                    <li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
                                    <li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
                                    <li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
                                </ul>
                            </apex:outputPanel>
                        </apex:form>
                    </apex:outputPanel>                     
                </div>
        </div>
public与共享类myController{
public ApexPages.StandardSetController setCtrl{get;set;}
公共字符串projId{get;set;}
公共字符串clientName{get;set;}
私有列表TicketList=新列表();
公共myController()
{
projId=ApexPages.currentPage().getParameters().get('id');
clientName=[从项目中选择Client\uu r.Name,其中Id=:projId]。Client\uu r.Name;
setCtrl=new ApexPages.StandardSetController(Database.getQueryLocator([选择票据编号、名称、状态、描述、解析描述、从票据创建日期,其中项目:按创建日期描述的项目顺序]);
ticketList=(List)setCtrl.getRecords();
setCtrl.setPageSize(5);
}
公共整数getNewStatusCount(){
返回[从Ticket_uuc中选择count(),其中Project_uc=:projId和status_uc='New'];
}
公共整数getWorkingStatusCount(){
返回[从Ticket_uc中选择count(),其中Project_uc=:projId和status_uc='Working'];
}
公共整数getResolvedStatusCount(){
返回[select count(),其中项目为:projId,状态为“已解决”;
}
公共整数getClosedStatusCount(){
返回[从Ticket_uuc中选择count(),其中Project_uc=:projId和status_uc='Closed'];
}
公共整数getCancelledStatusCount(){
返回[select count()(从票证c中选择),其中项目c=:项目,状态c='Cancelled'];
}
公共整数GetRecoveredStatusCount(){
返回[从Ticket_uuc中选择count(),其中Project_uc=:projId和status_uuc='重新打开'];
}
公共布尔hasnet{
得到{
返回setCtrl.getHasNext();
}
}
公共布尔hasPrevious{
得到{
返回setCtrl.getHasPrevious();
}
设置
}
公共整数页码{
得到{
返回setCtrl.getPageNumber();
}
设置
}
公共整数总页数{
得到{
totalPages=math.ceil((双精度)setCtrl.getResultSize()/setCtrl.getPageSize()).intValue();
返回总页数;
}
设置
}
首先公开无效(){
setCtrl.first();
}
公众假期最后(){
setCtrl.last();
}
公开作废以前的(){
setCtrl.previous();
}
下一个公共空间(){
setCtrl.next();
}
公共列表getTickets()
{
return(List)setCtrl.getRecords();
}
公共空过滤器状态(){
字符串myParam=apexpages.currentpage().getparameters().get('myParam');
setCtrl=new ApexPages.StandardSetController(Database.getQueryLocator([选择票证编号、名称、状态、描述、解析描述、从票证创建数据,其中项目:projId和状态:myParam ORDER BY CreatedDate DESC]);
setCtrl.setPageSize(5);
}
}
以下是VF代码:

                <div class="contact-form">


                    <apex:outputPanel id="contactForm">
                        <apex:form >
                            <ul class="filteredView">
                                <li>
                                    <apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
                                </li>
                                <li>
                                    ({!NewStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
                                        <apex:param name="myParam" value="New"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!WorkingStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
                                        <apex:param name="myParam" value="Working"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ResolvedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
                                        <apex:param name="myParam" value="Resolved"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ClosedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
                                        <apex:param name="myParam" value="Closed"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!CancelledStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
                                        <apex:param name="myParam" value="Cancelled"/>
                                    </apex:commandLink>
                                </li>
                                <li id="last">
                                    ({!ReopenedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
                                        <apex:param name="myParam" value="Reopened"/>
                                    </apex:commandLink>
                                </li>
                            </ul>
                            <h5>
                                TICKETS
                            </h5> 
                            <table width="95%" border="1" cellpadding="5">
                                <tr align="left">
                                    <th style="width:25px;">Ticket#</th>
                                    <th style="width:200px;">Subject</th>
                                    <th>Description</th>
                                    <th style="width:50px;">Status</th>
                                    <th style="width:75px;"></th>
                                </tr>
                                <apex:repeat value="{!tickets}" var="ticket">
                                    <tr>
                                        <td>{!ticket.Ticket_Number__c}</td>
                                        <td>{!ticket.Name}</td>
                                        <td>{!ticket.Description__c}</td>
                                        <td>{!ticket.Status__c}</td>
                                        <td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
                                <ul>
                                    <li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
                                    <li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
                                    <li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
                                </ul>
                            </apex:outputPanel>
                        </apex:form>
                    </apex:outputPanel>                     
                </div>
        </div>

                <div class="contact-form">


                    <apex:outputPanel id="contactForm">
                        <apex:form >
                            <ul class="filteredView">
                                <li>
                                    <apex:outputLink value="/tickets?id={!projId}">View All</apex:outputLink>
                                </li>
                                <li>
                                    ({!NewStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" New" rerender="contactForm">
                                        <apex:param name="myParam" value="New"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!WorkingStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Working" rerender="contactForm">
                                        <apex:param name="myParam" value="Working"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ResolvedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Resolved" rerender="contactForm">
                                        <apex:param name="myParam" value="Resolved"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!ClosedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Closed" rerender="contactForm">
                                        <apex:param name="myParam" value="Closed"/>
                                    </apex:commandLink>
                                </li>
                                <li>
                                    ({!CancelledStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Cancelled" rerender="contactForm">
                                        <apex:param name="myParam" value="Cancelled"/>
                                    </apex:commandLink>
                                </li>
                                <li id="last">
                                    ({!ReopenedStatusCount})
                                    <apex:commandLink action="{!filterStatus}" value=" Reopened" rerender="contactForm">
                                        <apex:param name="myParam" value="Reopened"/>
                                    </apex:commandLink>
                                </li>
                            </ul>
                            <h5>
                                TICKETS
                            </h5> 
                            <table width="95%" border="1" cellpadding="5">
                                <tr align="left">
                                    <th style="width:25px;">Ticket#</th>
                                    <th style="width:200px;">Subject</th>
                                    <th>Description</th>
                                    <th style="width:50px;">Status</th>
                                    <th style="width:75px;"></th>
                                </tr>
                                <apex:repeat value="{!tickets}" var="ticket">
                                    <tr>
                                        <td>{!ticket.Ticket_Number__c}</td>
                                        <td>{!ticket.Name}</td>
                                        <td>{!ticket.Description__c}</td>
                                        <td>{!ticket.Status__c}</td>
                                        <td><apex:outputLink value="/detail?id={!projId}&ticketId={!ticket.Id}">View Details</apex:outputLink></td>
                                    </tr>
                                </apex:repeat>
                            </table>
                            <apex:outputPanel rendered="{!(tickets.empty == false)}" styleClass="pagination" >
                                <ul>
                                    <li><apex:commandLink id="first" value="First" action="{!first}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="prev" value="Prev" action="{!previous}" rendered="{!hasPrevious}" /></li>
                                    <li><apex:commandLink id="next" value="Next" action="{!next}" rendered="{!hasNext}" /></li>
                                    <li><apex:commandLink id="last" value="Last" action="{!last}" rendered="{!hasNext}" /></li>
                                    <li><apex:outputText value="Page {!pageNumber} of {!totalPages}" /></li>
                                </ul>
                            </apex:outputPanel>
                        </apex:form>
                    </apex:outputPanel>                     
                </div>
        </div>

  • 查看所有
  • ({!NewStatusCount})
  • ({!WorkingStatusCount})
  • ({!ResolvedStatusCount})
  • ({!ClosedStatusCount})
  • ({!CancelledStatusCount})
  • ({!重新打开状态计数})
票 票# 主题 描述 地位 {!车票,车票号码} {!票子。名字} {!票。描述{u_c} {!票证。状态{u_c} 查看详细信息