1
votes

I'm trying to access a csv document in my Document sObject via apex (in order to parse the csv). I know how to parse CSV one I get the data (there are many articles on that part), but I'm not sure how to grab the document from the documents sObject in the first place!

How do I reference the CSV document (in sObject Document) from Apex?

I did see that a URL is returned from the following query:

SELECT body From Document WHERE name = 'myCSV'

That returns something like:

/services/data/v32.0/sobjects/Document/00000UptFER/Body

Do I need to point the parser to that address?

Thank you!

1

1 Answers

1
votes

tostring() is the solution.

Document d = [SELECT id, body 
                  FROM Document 
                  WHERE Name='myCSV' LIMIT 1];

string strBody = d.body.tostring();