function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Zachariah RosenbergZachariah Rosenberg 

Accessing CSV data in developer console

I'm trying to use CSV data in an apex class. There are many articles written about how to parse csv data in apex, but not many on the first part: accessing the csv data in apex. I've looked into import wizard (and data loader) but my csv data is not being uploaded into any sobjects. Rather, the csv data will be used for a SOQL query.

Ultimately I'd like the following query to be able to use my csv data:
SELECT Object.Name Object.custom_field__c FROM Object WHERE custom_field__c in :[csv data]

How can I make this happen?

Thank you so much!
James (CloudAnswers)James (CloudAnswers)
It sounds like you need to get the contents of the CSV file into a string, then parse it so you can access/collect the values into a List<String> or Set<String> to use in your query.

Your CSV file can be uploaded as an attachment, document, or just uploaded directly into a visualforce page by the user.  At that point the controller can access the csv file as a string, use split('\n') and split(','), and get those values out.
KevinPKevinP
well, you can always parse your csv into a list of data to use it like that. 

Something like 
CSV Parser (https://developer.salesforce.com/page/Code_Samples#Parse_a_CSV_with_APEX) -> List<String> 
James (CloudAnswers)James (CloudAnswers)
Here is a blog post detailing how to get the csv via upload and how to parse it:
http://www.sfdcpoint.com/salesforce/import-csv-file-using-apex-visualforce/

You should combine it with Kevin's suggestion through because his link has a more comprehensive csv parser.