Is it possible to construct a SOQL query with a list literal in the WHERE clause? My use case is that the data loader cannot handle child relationships/subqueries needed for my search, but I can get the full list of IDs to export and would like to submit a query along the lines of

[Select Id, Name, ... from Account WHERE Id in ('Id1', 'Id2',... ) ]

Since this is the DataLoader, I can't just use a variable list either. Or does someone know an alternate way to export queried data?

  • Your question subject and content seem to disagree with each other, but you absolutely can include a comma separated list in a WHERE clause using IN('Id1','Id2,...) – Todd Sprinkel Jul 21 '15 at 4:23
  • Someone edited my title to make it incorrect. Fixed. – LucidLunatic Jul 21 '15 at 4:34
  • How many elements may your list have (top limit if you have in mind) ? – Amit Bangad Jul 21 '15 at 5:36
  • Several thousand. For what I'm looking at currently, ~3000, but in principle up to 10k. – LucidLunatic Jul 21 '15 at 18:58

If you cannot get an answer or the list in lengthy, What I have done in the past is:

  1. Create boolean Flag named ExtporData__c on the object
  2. Updated all accounts via data loader using CSV with ID and ExportData__c field that should be exported

then in the data loader for export I simply used EmportData__c = true in the where clause

| improve this answer | |
  • Ah, that's clever. If it comes to it, I'll do that. – LucidLunatic Jul 21 '15 at 4:35
  • Fields like this are extremely useful, I might recommend using a number or text field though in case you ever have a case where you need to compare multiple sets of records. In our org, we have a field called temp__c on pretty much every object for this sort of scenario. Of course, you'll only want to make this available to admins though... – Todd Sprinkel Jul 21 '15 at 4:38

If you haven't got the answer yet, Try these steps :

  1. Query all possible Id's which should be included in your IN Clause.
  2. Use notepad++ to add '' into each id's and an use this in the [edit] SOQL statement.
  3. In Data loader just replace this query and export.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.