简体   繁体   English

Salesforce API查询的SOQL分页

[英]SOQL Pagination for Salesforce API queries

Is there an efficient way to page through results from a SOQL query without bringing all the query results back and then discarding the majority of them? 是否有一种有效的方法来浏览SOQL查询的结果,而不会将所有查询结果返回,然后丢弃其中的大部分?

As an example, I'd like to be able to to page through the complete list of contacts showing 10 records at a time. 作为一个例子,我希望能够翻阅一次显示10条记录的完整联系人列表。 I don't have the need to sort by any particular field. 我没有必要按任何特定领域排序。

Currently the most efficient solution I've found that will work with any SOQL query through the partner API is to persist the sObjects returned from the initial QueryResult and the query locator incase a page is requested outside the current results. 目前,我发现通过合作伙伴API处理任何SOQL查询的最有效的解决方案是保留从初始QueryResult和查询定位器返回的sObjects,以便在当前结果之外请求页面。

This required a level of paging support on top of the Salesforce QueryResult. 这需要在Salesforce QueryResult之上提供一定级别的分页支持。

Ie When a page is requested sObjects may be required from: 即当请求页面时,可能需要sObjects:

  • The current (cached) QueryResult 当前(缓存)的QueryResult
  • A subsequent QueryResult that can be fetched using the query locator 可以使用查询定位器获取的后续QueryResult
  • A prior QueryResult 先前的QueryResult
  • Some combination of all three. 三者的一些组合。

If the page spans two (or more) QueryResults an artifical QueryResult will need to be created with all the required records. 如果页面跨越两个(或更多)QueryResults,则需要使用所有必需记录创建人工QueryResult。

Update for Spring 2012 Release 2012年春季发布更新

Looks like there is new functionality coming that will add OFFSET support to SOQL. 看起来有新的功能将为SOQL添加OFFSET支持。 Eg 例如

SELECT Name FROM Merchandise__c WHERE Price__c > 5.0 ORDER BY Name LIMIT 50 OFFSET 100

See Spring '12 Force.com Platform Release - OFFSET added to SOQL (Pilot) 参见Spring '12 Force.com平台版本 - OFFSET添加到SOQL(Pilot)

Update for Summer 2012 Release 2012年夏季发布更新

OFFSET is now GA (General Availability?) OFFSET现在是GA (一般可用性?)

you can use a auto-number filed to do pagination at server side. 您可以使用自动编号字段在服务器端进行分页。 this field can be used after 'order by' clause, it can act as a index field. 这个字段可以在'order by'子句之后使用,它可以作为索引字段。

I've done pagination like what you side. 我像你一样做了分页。 but I got another problem, I can't do sort in server side at the same time. 但是我遇到了另一个问题,我不能同时在服务器端进行排序。 because sort and pagination both need add column after 'order by' clause. 因为排序和分页都需要在'order by'子句后添加列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM