You need to sign in to do that
Don't have an account?

Test.LoadData System.StringException: Unknown field
I'm trying to write a test class and load bunch of test lead's data but for some reason when I call the static resource (that has my CSV) is not recognizing the custom fields. Example, Lead_insurance_Id__c
My CSV file - static resource:
My test class:
Error message:

Seems like the standard Salesforce fields didn't cause any execptions but custom fields did (I tried other one beside Lead_Insurance_Id__c) and I still got the same error message.
P.S:
I've tried to change my CSV header to all of these formats but non helped:
LEADS_INSURANCE_ID__c
Leads_insurance_Id__c
Lead.DLeads_insurance_Id__c
Insurance ID (Field's label)
My CSV file - static resource:
// Example of how my CSV looks like Id, Firstname, Lastname, Leads_Insurance_ID__c,..etc 000012, Fares, Alsyoufi, 12184111, ..etc 000011, Fare,syoufi, 12184211, ..etc 000013, Fares, syouf, 12184311, ..etc
My test class:
@isTest global class DataUtil { static testmethod void testLoadData() { // Load the test accounts from the static resource List<sObject> ls = Test.loadData(Account.sObjectType, 'TestData'); } }
Error message:
Seems like the standard Salesforce fields didn't cause any execptions but custom fields did (I tried other one beside Lead_Insurance_Id__c) and I still got the same error message.
P.S:
I've tried to change my CSV header to all of these formats but non helped:
LEADS_INSURANCE_ID__c
Leads_insurance_Id__c
Lead.DLeads_insurance_Id__c
Insurance ID (Field's label)
YOUR CSV headers are
API Names (LEADS_INSURANCE_ID__c) ? As both didn't work in my case.
There is an incideous little devil-in-the-details issue here, and it's known as the Byte Order Mark (BOM)(https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding). In short, it's an invisible character that certain programs like Excel include when it encodes CSV content as UTF-8 (even though it's not recommended) and it causes Salesforce's parser to fail.
You can view and change the file encoding of a CSV in programs like VSCode. I did this, changed the encoding to plain UTF-8, reuploaded the static resource and...VIOLA. Things worked.
Please mark this as best answer if it worked for you, so other unfortunate souls dealing with the trash monster that is BOM can resolve it more quickly than I did.
With thanks to: https://salesforce.stackexchange.com/questions/4372/cant-get-test-loaddata-method-to-run
Was stuck with a similar problem and your answer here helped in solving it :-)
If you are getting such kind of error please try to change the encoding format of CSV file you are uploading in static resoures from UTF-8 with BOM to plain UTF-8 .
You can do it from Visual Stdio .
Follow the steps to change encoding -
- Open the CSV file you want to upload in Visual Stdio Code.
- Now at bottom right you can see encoding format.
- .

- Click on it and UTF-8 with BOM and then click on Save with Encoing and then select encoding type UTF-8.
Thankyou ;-)