Loading

Test classes fail with error 'System.SObjectException: Script-thrown exception'

Udgivelsesdato: Oct 13, 2022
Beskrivelse

The test classes can load the data from the static resource dynamically for a custom setting. For example, custom setting (XYZ__c) records and a static resource name of myResource, make the following call:
 
List<sObject> ls = Test.loadData(XYZ__c.sObjectType, 'myResource');

However, while executing the test classes who load the test data dynamically from static resources, there could be an exception System.SObjectException: Script-thrown exception 
Stack Trace: Class.System.Test.loadData: line 53, column 1 followed by class.method name.

This error may occur due to following 2 reasons.
  • The default maximum size of Custom Settings (10000  KB) is is being hit while loading additional test data in the Test classes. 
  • The static resource is referencing to hard coded Ids which may not be available to the organization.
Løsning

The default maximum size of Custom Settings (10000  KB) is being hit while loading additional test data in the Test classes:
  • Go to setup
  • Navigate to develop | Custom Settings
  • Click on the button Get Usage to see custom settings data used in your organization and if you are closed to the limit or already hitting the limit.
Note: The error is related to all custom setting data storage instead of the custom setting used in the test class.

The static resource is referencing to hard-coded Ids which may not be available to the Organization:

Please remove the hard-coded references from the custom setting or Create all test data before calling the Test.startTest method in the test classes.

Also follow the best practices as mentioned in the Testing Best Practices
Vidensartikelnummer

000385513

 
Indlæser
Salesforce Help | Article