Timeline for Convert SObject.toString output to a CSV value line (Regexp..)
Current License: CC BY-SA 3.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 28, 2019 at 12:51 | comment | added | Laureant | It doesn't exactly handle everything. I sadly bumped into a situation where its not parsing a CSV file correctly. The file can be opened without any issues in Excel/Pages/LibreOffice, but the CSV Parser seems to have issues with it from the second row onwards. It looks like it eats the first character of the second row, and from then on, the whole thing is a mess. Any alternatives for this? | |
May 20, 2013 at 15:18 | history | edited | zachelrath | CC BY-SA 3.0 |
formatting edits
|
Nov 26, 2012 at 22:06 | vote | accept | Robert Sösemann | ||
Nov 20, 2012 at 0:23 | comment | added | zachelrath |
@RobertS, as I mentioned at the top of my post, "Files" are just Blobs, and Blobs can be created just by doing Blob.valueOf(someString) , and you don't have to do this until you're ready to send the final file, i.e. in the finish method of your Batch Apex. So store the String as an instance variable on your Batch class, and add to it during each iteration of the execute method. Then in the finish method, just call Blob.valueOf(csvFileString) , and set this as the body of a Messaging.EmailFileAttachment
|
|
Nov 19, 2012 at 23:50 | comment | added | Andrew Fawcett | BTW, I also just noticed some CSV escaping and unescaping functions on the String class in Apex, never seen those before! :) | |
Nov 19, 2012 at 23:49 | comment | added | Andrew Fawcett | Yes Marty Chang did an excellent job! We extended his library to support parsing larger CSV files via Batch Apex Iterators here, developer.financialforce.com/customizations/… | |
Nov 19, 2012 at 20:37 | comment | added | Robert Sösemann | @zachelrath, to use Batch writing files would need to be chunkifiable in any way. But as Files don't allow an append there is no way to do this. Or do you see one? | |
Nov 19, 2012 at 17:21 | comment | added | zachelrath |
@RobertS , see my clarification of the first solution. I think you want the "Export" button to kick off a Batch Apex process, whose finish method will send an Email with the generated CSV. Each execute method in Batch APex gets a fresh set of governor limits, so this will solve the Too Many Script Statements limit . To write an IETF RFC 4180 compliant CSV file (which you should do if you want your customers to actually be able to open your CSV files), you'll NEED to use something like String.escapeCsv() on each of your SObject rows' field values.
|
|
Nov 19, 2012 at 17:18 | history | edited | zachelrath | CC BY-SA 3.0 |
changed description of 1st solution
|
Nov 19, 2012 at 16:47 | history | edited | zachelrath | CC BY-SA 3.0 |
changed some section headings
|
Nov 19, 2012 at 12:43 | comment | added | Robert Sösemann | zachelrath: I don't get your solution. I don't want to parse CSV. I just need to write a CSV and I need to use System code to not run into limits.. Creating a CSV in browser memory is a too hacky solution for me. | |
Nov 19, 2012 at 12:41 | history | edited | zachelrath | CC BY-SA 3.0 |
described how to parse a CSV blob in JavaScript
|
Nov 19, 2012 at 12:35 | comment | added | zachelrath | Can you create the blob client-side? That's what I do. Create it using JavaScript, then sent to Apex using Visualforce Action, JS Remoting, or POST data. | |
Nov 19, 2012 at 12:32 | comment | added | eyescream | You're getting my +1 because it's a useful tool for future use. But I believe it won't help in this case. "I am running into ToManyStatements Limits while creating a CSV blob", the very first line in the question ;) | |
Nov 19, 2012 at 12:29 | history | answered | zachelrath | CC BY-SA 3.0 |