[SalesForce] Test.loadData() static resource text/csv vs. text/comma-separated-values

I am trying load a csv of User data for an Apex test from a static resource using Test.loadData(). When I upload the csv as a static resource, Salesforce gives is a MIME type of text/comma-separated-values which is not a MIME type supported by Test.loadData() ( http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm#apex_System_Test_loadData ) and so I get an error telling me as much when I run the test.

System.TypeException: Content type not allowed for Test.loadData():
text/comma-separated-values

Has anyone encountered this? Does my static resource need a MIME type of text/csv instead of text/comma-separated-values in order to use it with Test.loadData() or do I have another problem? Is there any trick to forcing this MIME type?

Best Answer

I can reproduce the error (which is a pretty clear anyway) so you will need to use ContentType of "text/csv".

I can think of 2 ways of getting the ContentType (labelled "MIME Type" in the UI) to be the required "text/csv":

  • Install a different browser and use that to do the uploads as AFAIK it is the browser that infers the content type from the file extension and/or file content; Chrome on a Mac uploads a CSV file with the file extension .csv as "text/csv".
  • Use the Force.com IDE or the Ant migration tools to download the static resource(s), then fix the contentType element in the .resource-meta.xml file(s), then upload them. (I used the Force IDE to turn my working "text/csv" static resource into a failing "text/comma-separated-values" one.)