Can't get Test.loadData method to run

As I remember, I discovered 3 details about the file to get this working. Ended up with 120 records in 14KB, UTF-8 without BOM file uploaded as txt/csv in Static Resources.

  1. For "System.UnexpectedException" error, the size had to be <20k. I reduced the number of records to 120, making it ~14K in size.

  2. "System.StringException: Unknown field:" - parser was reading the BOM; saved file without. That is probably what happened for line 11 (in the posted code). //but i have no idea what i did to the csv file

  3. "System.StringException: CSV Parse error:" - yep, found one buried in the data; there are a LOT of fields in these records (don't ask).

still waiting for that well placed smack on the head


I was actually having a similar issue when I received the System.StringException Unknown field:. I compared this file with the other files which worked in the past and they were identical.

After doing many tried I found that it was the issue with file formatting that was happening in the background when using MS Excel. So I just created the same CSV file in Google SpreadSheet and downloaded it as CSV.

Uploaded that CSV in static resource and boom tests started passing.

I know the above comment already mentioned that it's a file format issue but I am sharing what resolved my issue. It may be helpful for someone.

Thanks.

Tags:

Apex

Unit Test