简体   繁体   English

如何在Salesforce中使用批量API和WHERE子句

[英]How to use Bulk API with WHERE clause in Salesforce

I want to use Bulk API of Salesforce to run queries of this format. 我想使用Salesforce的Bulk API来运行此格式的查询。

Select Id from Object where field='<value>'.

I have thousands of such field values and want to retrieve Id of those objects. 我有数千个这样的字段值,并希望检索这些对象的Id。 AFAIK, Bulk query of Salesforce supports only one SOQL statement as input. AFAIK,Salesforce的批量查询仅支持一个SOQL语句作为输入。

One option could be to form a query like 一种选择可能是形成一个类似的查询

Select Id,field where field in (<all field values>)

but problem is SOQL has 10000 characters limitation. 但问题是SOQL有10000个字符的限制。

Any suggestions here? 这里有什么建议?

Thanks 谢谢

It seems like you are attempting to perform some kind of search query. 您似乎正在尝试执行某种搜索查询。 If so you might look into using a SOSL query as opposed to SOQL as long as the fields you are searching are indexed by SFDC. 如果是这样,您可能会考虑使用SOSL查询而不是SOQL,只要您搜索的字段由SFDC编制索引即可。

Otherwise, I agree with Born2BeMild. 否则,我同意Born2BeMild。 Your second approach is better and breaking up your list of values into batches would help get around the limits. 您的第二种方法更好,将您的值列表分成批次将有助于绕过极限。

It would also help if you described a bit of your use case in more detail. 如果您更详细地描述了一些用例,它也会有所帮助。 Typically queries on a dynamic set of fields and values doesn't always yield the best performance even with the bulk api. 通常,对动态字段和值集的查询并不总能产生最佳性能,即使使用批量api也是如此。 You are almost better off downloading the data to a local database and exploring the data that way. 将数据下载到本地数据库并以这种方式探索数据几乎可以。

You could break those down into batches of 200 or so values and iteratively query Salesforce to build up a result set in memory or process subsets of the data. 您可以将这些值分解为大约200个左右的值,并迭代查询Salesforce以在内存中构建结果集或处理数据的子集。

You would have to check the governor limits for the maximum number of SOQL queries though. 您必须检查调控器限制以获取最大SOQL查询数。 You should be able to track your usage via the API at runtime to avoid going over the maximum. 您应该能够在运行时通过API跟踪您的使用情况,以避免超出最大值。

The problem is that you are hitting the governor limits. 问题是你正在达到州长限制。 Saleforce can only process 200 records at a time if its coming from a database. 如果Saleforce来自数据库,它一次只能处理200条记录。 Therefore to be able to work with all this records first you need to add all records to a list for example: 因此,为了能够首先处理所有这些记录,您需要将所有记录添加到列表中,例如:

 List<Account> accounts= [SELECT id, name, FROM Account];

Then you can work with the list accounts do everything you need to do with it then when you done you can update the database using: 然后,您可以使用列表帐户执行您需要执行的所有操作,然后在完成后可以使用以下命令更新数据库:

Update accounts;

this link might be helpful: https://help.salesforce.com/apex/HTViewSolution?id=000004410&language=en_US 此链接可能会有所帮助: https//help.salesforce.com/apex/HTViewSolution?id = 000004410&language = en_US

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

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