I cannot get past various system exceptions trying to use the loadData method. It seems to be something with the csv file; changing it alters the cause of failure.

I am using data from production extracted today with DataLoader, Win7, and Force.com IDE. I copied the statement straight from the example and modified it to List<sObject> td = Test.loadData(Lead.sObjectType, 'testLeads200'); I have also verified both the test class and the class under test are using api 26.

When I leave encoding as ANSI, the failure is System.UnexpectedException: Salesforce System Error: 1067929596. Changing to UTF-8, with and without Unix formatted EOL, it seems to be readable, but... Leaving the double quote qualifiers in place gives a System.StringException: CSV Parse error: Found unescaped quote. Removing the qualifier, the failure becomes System.StringException: Unknown field: Division (or whatever the first header becomes after removing column). When uploading the file to Static Resources with Firefox, MIME type is text/csv; with Chrome, it is application/vnd.ms-excel.

I could find only a couple related issues- some comments on an answer here in our beloved StackExchange about the MIME type(which one not specified), and a self-answered post on our beloved developerforce boards about rows having no value for date fields (tried removing all date fields). Does anyone have an idea, or a well placed smack on the head?

private class AggregateRefreshTest {

//TODO: increase AggregateRefresh unit tests

//this is just a basic happy path run to start coverage
static testMethod void myUnitTest() {

    //added in the example code from apex reference to check sanity
    //initially was having the same issues; works now -
    //but i have no idea what i did to the csv file
    List<sObject> ls = Test.loadData(Account.sObjectType, 'testAccounts');
    System.assert(ls.size() == 3);

    //always fails at this statement
    List<sObject> td = Test.loadData(Lead.sObjectType, 'testLeads200');
    //verify loaded
    system.assert(false);  //another sanity check
    System.assertEquals(200, td.size(), 'Static Resource Test Data did not load');

    ID batchprocessid; Integer batch= 200; String fld='Division';
    String[] vals = new String[]{};

    for (sObject l : td){
    }   //for (sObject l : td)

        batchprocessid = Database.executeBatch(new AggregateRefresh(fld, vals), batch);

    AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, 
        CreatedBy.Email, CompletedDate, CreatedDate FROM AsyncApexJob WHERE Id = :batchprocessid];

    System.assertEquals('Completed', a.Status, 'AsyncApexJob Status');

}   //static testMethod void myUnitTest()

}   //private class AggregateRefreshTest
  • 2
    Since you have an error number, I would encourage you to contact support. When there is an error number it makes it easier for salesforce support to narrow down the cause. Also, when contacting support it'd be great if you could remove as much code as possible to get the simplest repro case possible.
    – Ryan Guest
    Nov 14, 2012 at 3:16
  • Are you using Linux or a distro to do this? How about extracting the CSV via Workbench and then trying that? Nov 14, 2012 at 3:59
  • @RyanGuest - Good point. After too many hours, I was caught up in seeing "progress" since the failure kept changing and not remembering this is a new feature.
    – zjeh
    Nov 14, 2012 at 12:18
  • 2
    Looks like a bug. If you file a case and give support a sample of the CSV that you believe should work, then I can fix it. You can also tweet me the case number at @rich_unger. Also, some of these types of bugs have already been ironed out in Winter13.
    – Rich Unger
    Nov 14, 2012 at 18:43
  • 3
    Was there ever an answer for this? I'm quite curious.
    – pchittum
    Jan 24, 2013 at 15:37

2 Answers 2


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

  • Great answer! I updated your formatting to increase readability and help me understand it. I'm looking at using Test.loadData(), and all of this is really good to know.
    – Matt K
    Aug 14, 2013 at 14:22
  • @MatthewKeefe Thanks! Hope it goes smoothly for you. Keep in mind I had these issues when the feature first came out; there may have been some tweaks that overcome these since then.
    – zjeh
    Aug 14, 2013 at 14:47

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.


  • I had the same issue, downloading the file from Google Sheet resolved it.
    – Json
    Nov 1, 2020 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .