You need to sign in to do that
Don't have an account?
Stender
Test code for incoming CSV
Hello,
I am having trouble writing test code for an incoming .csv file. My functioanlity actually has two steps, one where a .csv is createed by a VF page and another that will 'consume' the data from the .csv and update records in SF. My idea was to use the test code for the 'export' portion of the project to be used as the test blobl for the 'import' portion. However, in my test code I can't use the 'getContent()' method for the current page to assign the export page as a blob. Any ideas on how else to do this?
Thanks,
Jeremy Stender
You will have to circumvent the process for retrieving the content of the CSV file and define a string that represents a sample for CSV content.
Make use of the Test.isRunningTest() in your Apex classes.
For example (with a static resource - but will be a similar concept for BLOB uploads too):
If you are using BLOB, convert your sample CSV file (a miniscule one will be best) into a BLOB string. Use that string and convert that back when you come to your test code.
Right, thats what I figured I needed to do. Was basically mock up the .csv and assign it to a Blob. My question though is how to indicate a 'new line' when creating the blob?. Right now what I have done is assigned each 'row' of the csv file to a different string (either hard-coded or using the same get() methods that the VF Export page does), and then concatenated them all into a big string file that I use to assign the blob. But I don't think it is working. Here is the relevant code:
The problem is that I am getting an error with the subsequent updates that happen, which first means that the assignment of the blobl and the 'parsing' of it happens correctly, but reading the debug log the it looks like it is just reading the file as on long row, rather than 12 separate rows like it should. I think getting to blob to correctly reflect how a .csv file is written with the correct 'new line' entry is all I really need now. Thanks again
Jeremy Stender
Error was being caused by something else. I have finished the code and it is working now. Thanks for the help!