1
votes

I want to use Bulk API of Salesforce to run queries of this format.

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

I have thousands of such field values and want to retrieve Id of those objects. AFAIK, Bulk query of Salesforce supports only one SOQL statement as input.

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.

Any suggestions here?

Thanks

3
It's worth updating the question with the business logic, since querying on so many field values is not considered a good idea for performance reasons. - Anup

3 Answers

2
votes

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.

Otherwise, I agree with 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. You are almost better off downloading the data to a local database and exploring the data that way.

1
votes

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.

You would have to check the governor limits for the maximum number of SOQL queries though. You should be able to track your usage via the API at runtime to avoid going over the maximum.

0
votes

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. 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