Search code examples
javasalesforcesoql

How to use Bulk API with WHERE clause in Salesforce


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


Solution

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