function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EalesieEalesie 

Custom Settings and Workflow causing Internal Server Error in Unit Tests

I have a Workflow that is settings fields using formula's that reference Custom Settings fields.  UI all works OK.  Apex Tests are causing an internal server error.

If I mark the test SeeAllData=True then, rather than creating the Custom Setting as part of the test data setup then all ok.  Create a new Custom Setting as part of test data markup - Internal Server Error.

Any ideas welcomed.
 
Mudasir WaniMudasir Wani

Hello,

Custom Settings are "Data" and as such are not part of the test-environment as of Spring '12.
Just like every object will have no records by default.
You need to create a new custom setting with values 

customsettingName__c setting = new customsettingName__c ();
setting.Name = 'Test Name'; setting.Value__c = 'Test Value';
insert setting;

EalesieEalesie
Thanks for your response, I am aware that custom settings need instantiating as part of test code, and it is this instantiation that is causing the issue.  If I use SeeAllData=True I can set the values to what I like - no issue.  Try to create as part of the Apex Test method - Internal Server Error....Think there is a bit of a platform bug here.