In a visual flow that is autolaunched on Opportunity creation. In it I have a lookup element to a custom setting that returns a string based on a date value.

When I run this in the UI and create an Opp everything works fine, but when I create an Opp while running an apex test class the custom setting lookup always returns null. Is there a reason this doesn't work in an apex test class or it is just a bug?

Another answer suggested rebuilding the custom settings records, which I did with no luck.

  • 1
    hierarchical or list custom setting?
    – cropredy
    Commented Jun 14, 2018 at 0:00

1 Answer 1


Custom Settings are treated as data, not metadata, in test context, and as such are not visible during the test run.

If you need that setting available during the course of your unit test (in Apex or Flow), the test or its associated @testSetup method needs to create and insert the Custom Setting value.

You must log in to answer this question.

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