gpt4 book ai didi

salesforce - 限制异常 : Too many query rows: 50001 from with count() aggregate function

转载 作者:行者123 更新时间:2023-12-01 11:01:46 34 4
gpt4 key购买 nike

我有一个 Visualforce 页面,我想在其中显示特定 sObject 表中记录数的计数。

在 Visualforce 页面中,我有一些相当简单的内容,例如:

<p>Client Account Count: {!ClientAccountCount}</p>

然后在 Controller 中:

// Return the number of clients
public integer getClientAccountCount() {
return [Select count() from Account where SomeCustomField__c = 'Client' limit 50000];
}

我认为使用 SOQL 中的 limit 子句我会很好,因为它每次最多只返回 50,000。然而,在实践中我仍然在生产组织中得到这个异常(exception):

09:29:12:179 SOQL_EXECUTE_BEGIN [108]|Aggregations:0|select count() from Account where SomeCustomField__c = 'Client' limit 50000

09:29:12:331 EXCEPTION_THROWN [108]|System.LimitException: Too many query rows: 50001

有没有安全的方法来执行此查询,不会导致我无法捕获的异常?

奇怪的是,如果我在生产中尝试以下作为匿名顶点,它工作正常并返回 50,000。

integer count = [select count() from Account where SomeCustomField__c = 'Client' limit 50000];

也许问题是导致问题的所有操作的查询行的累积数量,我需要在运行查询之前检查代码中的限制?


Force.com 讨论板上有一个类似的帖子 - Too many query rows on COUNT(*) function .我无法将 VF 页面设置为只读以增加查询行限制。

最佳答案

呸!我很确定我需要检查 SOQL 查询检索到的记录的累计数量。因此,虽然一个 SOQL 查询最多可以获取 50,000 条记录,但两个查询不能各获得 50,000 条记录。

猜猜我可以使用 Limits.getQueryRows() and Limits.getLimitQueryRows()如果需要,禁用 SOQL 查询。


我已经改变了 getClientAccountCount() 方法的工作方式。我认为只有 every 才能指示有多少行,因为聚合函数受到限制。

// Return the number of ad book clients
public string getClientAccountCount() {
System.debug(LoggingLevel.Debug, 'getClientAccountCount() - Current Query Rows: ' + Limits.getQueryRows() + '/' + Limits.getLimitQueryRows());
integer recordCount = [Select count() from Account where SomeCustomField__c = 'Client' limit 1001];
if(recordCount == 1001) { return '1000+'; }
return string.valueOf(recordCount);
}

这个想法 - Count the SOQL count() query as a single row query似乎值得推广。

关于salesforce - 限制异常 : Too many query rows: 50001 from with count() aggregate function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9984349/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com