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
sparkysparky 

batch apex test err if formula field references custom setting

I have a batch apex class, which references a formula field (custom field on CampaignMember) which in turn references a hierarchical custom settings object.  API v25.  I am inserting a record into this custom setting as the first part of my test.  I'm seeing the following behavior in my testmethod:

 

  • If I don't declare (SeeAllData = true) for my test, the entire thing gacks with the following err: FATAL_ERROR|System.UnexpectedException: Error processing messages(System Code)
  • If I declare (SeeAllData = true) that err does not occur (but I have other issues - i don't want to use all data)
  • If I remove the reference to the custom setting in the formula field, the error does not occur
  • The err occurs only in the test.  If I run the batch in production (with the setting populated) it runs fine

Seems like an internal SF bug - somehow the formula field is not able to access the values in the settings obj unless I use SeeAllData, even though I'm inserting a settings rec and everything else in the code is able to access it.

 

Can anyone confirm this issue?

 

Thanks much!