具有2000多条记录的salesforce对象的r-force cli查询



我刚刚发现了force-cli工具。如何查询2000多条记录?

我让它处理查询,但它只返回2000,我需要把它们都取出来。

force query select Id, Name from Custom_Object__c --format:csv > custom.csv

这个文件有大约10000条记录,而我只能得到前2000条。cli工具的文档没有提到很多细节,但它比我使用的工具快得多,R使用RForcecom库

您所需要做的就是使用包RForcecom中的bulkQuery函数。示例:

all_leads <- "SELECT Id FROM Lead WHERE CreatedDate < TODAY"
rforcecom.bulkQuery(rforce_session, all_leads,object="Lead") -> all_leads_df

Lead中今天之前的所有内容选择Id。我大约需要一分钟才能完成约70万行。

salesforcer包可以通过Bulk 1.0 API快速查询数百万条记录。下面是一个返回Contact对象上所有记录和字段的示例:

library(tidyverse)
library(salesforcer)
sf_auth(username, password, security_token)
# get all the fields on the Contact object (remove compound fields which 
# are not queryable via the Bulk API.
# https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/compound_fields.htm
contact_fields <- sf_describe_object_fields('Contact') %>% 
  filter(type != 'address', !grepl('Latitude|Longitude', name))
# build the SOQL
all_soql <- sprintf("SELECT %s FROM Contact", 
                    paste(contact_fields$name, collapse=","))
# query the records and fields
all_records <- sf_query(all_soql, "Contact", api_type="Bulk 1.0")
all_records
#> # A tibble: 2,039,230 x 58
#>   Id                 IsDeleted MasterRecordId AccountId   ...
#>   <chr>              <lgl>     <lgl>          <lgl>    
#> 1 0033s00000wycyeAAA FALSE     NA             NA       
#> 2 0033s00000wycyjAAA FALSE     NA             NA       
#> 3 0033s00000wycyoAAA FALSE     NA             NA
#> # ...

最新更新